Kubernetes: Difference between revisions
Line 62: | Line 62: | ||
With everything in place, you are ready to join the node to the master. To do this, go to the node's terminal and issue the command: |
With everything in place, you are ready to join the node to the master. To do this, go to the node's terminal and issue the command: |
||
sudo su |
|||
kubeadm join --token <TOKEN> <MASTER_IP:6443> |
|||
OR |
|||
kubeadm join 10.1.11.184:6443 --token 0lxezc.game230zg6jpa60g --discovery-token-ca-cert-hash sha256:74b34793d04696727b4dafe15ec82be3528f07af037c71e4a54e7475901bf627 |
|||
=Deploying a service= |
=Deploying a service= |
Revision as of 12:37, 17 May 2018
Requirements
3 Ubuntu VMs having:
Same version Having same resources LAN Connectivity
Installing dependencies
The first thing you must do is install the necessary dependencies. This will be done on all machines that will join the Kubernetes cluster. The first piece to be install is apt-transport-https (a package that allows using https as well as http in apt repository sources). This can be installed with the following command:
sudo apt-get update && apt-get install -y apt-transport-https
Our next dependency is Docker. Our Kubernetes installation will depend upon this, so install it with:
sudo apt install docker.io
Once that completes, start and enable the Docker service with the commands
sudo systemctl start docker sudo systemctl enable docker
Installing Kubernetes
sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add
Next add a repository by creating the file /etc/apt/sources.list.d/kubernetes.list and enter the following content:
deb http://apt.kubernetes.io/ kubernetes-xenial main
Save and close that file. Install Kubernetes with the following commands:
apt-get update apt-get install -y kubelet kubeadm kubectl kubernetes-cni
Initialize your master
With everything installed, go to the machine that will serve as the Kubernetes master and issue the command:
sudo kubeadm init
Before you join a node, you need to issue the following commands (as a regular user):
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
Deploying a pod network
You must deploy a pod network before anything will actually function properly.
Run kubectl apply -f [podnetwork].yaml with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
Here we will be installing the Flannel pod network:
sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/k8s-manifests/kube-flannel-rbac.yml
Issue the command
sudo kubectl get pods —all-namespaces
Joining a node
With everything in place, you are ready to join the node to the master. To do this, go to the node's terminal and issue the command:
sudo su kubeadm join --token <TOKEN> <MASTER_IP:6443>
OR
kubeadm join 10.1.11.184:6443 --token 0lxezc.game230zg6jpa60g --discovery-token-ca-cert-hash sha256:74b34793d04696727b4dafe15ec82be3528f07af037c71e4a54e7475901bf627
Deploying a service
At this point, you are ready to deploy a service on your Kubernetes cluster. To deploy an NGINX service (and expose the service on port 80), run the following commands (from the master):
sudo kubectl run --image=nginx nginx-app --port=80 --env="DOMAIN=cluster" sudo kubectl expose deployment nginx-app --port=80 --name=nginx-http
Go to your node and issue below command, you should see the service listed:
sudo docker ps -a,