Posted by Arjun Arjun on Wednesday 31st January 2018, 1 minute read

kubeadm - Setup kubenetes cluster on ubuntu 16.04

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

[email protected]:~$ 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

 [email protected]:~$ apt install

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

[email protected]:~$ systemctl start docker
[email protected]:~$ 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

[email protected]:~$  curl -s | apt-key add -

Add the kubernetes repo to your system

[email protected]:~$  cat < /etc/apt/sources.list.d/kubernetes.list  
deb kubernetes-xenial main  

Update repository list

[email protected]:~$  apt-get update

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

[email protected]:~$  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:

[email protected]:~$ 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:
You can now join any number of machines by running the following on each node
as root:
  kubeadm join --token 24fb38.98e1d033bd7d4e9c --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):

[email protected]:~$ sudo mkdir -p $HOME/.kube
[email protected]:~$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
[email protected]:~$ 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):

[email protected]:~$ sysctl net.bridge.bridge-nf-call-iptables=1
[email protected]:~$ kubectl apply -f

You can check your current node status with command

[email protected]:~$ 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,

[email protected]:~$ kubeadm join --token 24fb38.98e1d033bd7d4e9c --discovery-token-ca-cert-hash sha256:f1fffda887f34f62afcb9306b13926e6c009eb5c74ef4e1f8949bb54df797bcd

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

[email protected]: kubeadm token generate  

I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.