Skip to content

kubeadm – Setup kubenetes cluster on ubuntu 16.04

Last updated on February 10, 2018

Before installing Kubernetes, you have to install dependencies of Kubernetes. You have to install those dependencies in all of the nodes that you will join in the Kubernetes cluster.

Installing Dependencies

The first piece to be installed is apt-transport-https (a package that allows using HTTPS well as HTTP in apt repository sources). You can install it with below commond

root@arjun:~$ apt-get update && apt-get install -y apt-transport-https

We gonna use Docker as container engine, so let’s install it with below command

 root@arjun:~$ apt install docker.io

Once Docker is installed, start and enable the Docker service with the commands

root@arjun:~$ systemctl start docker
root@arjun:~$ systemctl enable docker

Here enable marks the service for starting up on boot, and start actually start the service immediately.

Install kubeadm

In the previous step, we have installed all the dependencies now install kubeadm.

Retrieve the key for the Kubernetes repo and add it to your key manager

root@arjun:~$  curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -

Add the kubernetes repo to your system

root@arjun:~$  cat < /etc/apt/sources.list.d/kubernetes.list  
deb http://apt.kubernetes.io/ kubernetes-xenial main  
EOF

Update repository list

root@arjun:~$  apt-get update

All set, now Install kubelet, kubeadm, kubectl and kubernetes-cni (a package that enables cni network on your machine)

root@arjun:~$  apt-get install -y kubelet kubeadm kubectl kubernetes-cni

You need to do all the above steps on all of your machines that you want to run kubernetes

Initialize your master

To initialize the master, pick one of the machines you previously installed kubeadm on, and run:

root@arjun:~$ kubeadm init

you will get similar output in your terminal…

...
...

Your Kubernetes master has initialized successfully!
To start using your cluster, you need to run the following 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
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/
You can now join any number of machines by running the following on each node
as root:
  kubeadm join --token 24fb38.98e1d033bd7d4e9c 172.31.9.30:6443 --discovery-token-ca-cert-hash sha256:f1fffda887f34f62afcb9306b13926e6c009eb5c74ef4e1f8949bb54df797bcd

To make kubectl work for your non-root user, you might want to run these commands (which is also a part of the kubeadm init output):

ubuntu@arjun:~$ sudo mkdir -p $HOME/.kube
ubuntu@arjun:~$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
ubuntu@arjun:~$ sudo chown $(id -u):$(id -g) $HOME/.kube/config

Make a record of the kubeadm join command that kubeadm init outputs. You will need this in a moment.

Deploying a pod network

You must deploy a pod network before anything will actually function properly. I’ll demonstrate this by installing the Romana pod network. This can be done with two commands (run on the master):

root@arjun:~$ sysctl net.bridge.bridge-nf-call-iptables=1
root@arjun:~$ kubectl apply -f https://raw.githubusercontent.com/romana/romana/master/containerize/specs/romana-kubeadm.yml

You can check your current node status with command

ubuntu@arjun:~$ kubectl get nodes

Setup kubernetes on other node

Just do all the steps on the node but not kubeadm init and pod network setup and run the join command,

root@node-01:~$ kubeadm join --token 24fb38.98e1d033bd7d4e9c 172.31.9.30:6443 --discovery-token-ca-cert-hash sha256:f1fffda887f34f62afcb9306b13926e6c009eb5c74ef4e1f8949bb54df797bcd

If you forgot the cluster token, you can generate a new one with the command:

root@arjun: kubeadm token generate  
24fb38.98e1d033bd7d4e9c
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments