, , , , , , , , , ,

About Kubernetes

Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications.

The below are the step by step guide to install Kubernetes on top of Ubuntu 16.04. Here, one machine will act as the master and the other two machines will be the node. You can then replicate the same steps to deploy the Kubernetes cluster onto your prod.

Steps to follow for the installation of Kubernetes:

The below steps have to be executed on both master and nodes.

Step 1: Login as a root user to execute the below commands

$ sudo su
# apt-get update

Step 2: We need to turn off the Swap space to avoid the erros, then we need to open the fstab file and comment the line with swap partition.

# swapoff -a
# nano /etc/fstab


Step 3: Next to change the hostname of master and node machines, better to have names easily recognized as master and node.

# nano /etc/hostname


Step 4: Next to update the hosts file with IP’s of master and nodes. Execute the below command to find the IP in both master and nodes.

# ifconfig


Step 5 : Now have to edit the hosts file to update the IP’s of master and nodes in both master and node machines.

# nano /etc/hosts


Step 6 : Next we will make above IP address, static ip, we need to edit the network interface files, Execute the below command to update.

# nano /etc/network/interfaces

Now have to add the below lines to the file

auto enp0s8
iface enp0s8 inet static
address <IP-Address-Of-Machine>


Step 7 : Now have to restart the machines.

Step 8 : Once the machines are up, We have to install the OpenSSH-Server on machines. Execute the below command.

# sudo apt-get install openssh-server

Step 9 : Next we need to install the Docker, because Docker images will be used for managing the containers in the cluster. Execute the below commands:

# sudo su
# apt-get update
# apt-get install -y docker.io

Step 10 : Next we need to install three essential components for setting up Kubernetes environment. kubeadm, kubectl, and kubelet. Before that we need to execute the below commands.

# apt-get update && apt-get install -y apt-transport-https curl
# curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
# cat </etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
# apt-get update

Step 11 : Now we will install the 3 essential components. Kubelet is the lowest level component in Kubernetes. It’s responsible for what’s running on an individual machine. Kuebadm is used for administrating the Kubernetes cluster. Kubectl is used for controlling the configurations on various nodes inside the cluster.

# apt-get install -y kubelet kubeadm kubectl

Step 12 : Next, we need to update the configuration file of Kubernetes. Execute the below command:

# nano /etc/systemd/system/kubelet.service.d/10-kubeadm.conf

Now add the following line after the last “Environment Variable” to the configuration and save the changes.



Now we have successfully install Kuberenetes on both the master and node machines.
Still now, only the Kubernetes environment has been setup. now, we will be installalling  Kubernetes completely, by moving onto the next 2 phases, where we will individually set the configurations in both machines.

Steps Only For Kubernetes Master

These steps will only be executed on the master.

Step 1 : We will now start our Kubernetes cluster from the master’s machine. Update the Master IP address and execute the below command:

# kubeadm init --apiserver-advertise-address= --pod-network-cidr=

Screenshot from 2018-09-27 16-58-33

From the above output we have to execute the below commands to use kubectl & join nodes to cluster.
From the below output. execute them as a non-root user. This will enable us to use kubectl from the CLI.


The below output should also be saved for future. This will be used to join nodes to your cluster.


Step 2 : Execute the below command to enable kubectl.

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

Step 3 : To verify, if kubectl is working or not, execute the below command:

$ kubectl get pods -o wide --all-namespaces


Step 4 : We will now notice from the above screenshot, that all the pods are running except one: ‘kube-dns’. For resolving this we will install a pod network. To install the CALICO pod network, execute the below command

$ kubectl apply -f https://docs.projectcalico.org/v3.0/getting-started/kubernetes/installation/hosted/kubeadm/1.7/calico.yaml


After some time, you will notice that all pods shift to the running state.


Step 5: Next, we will install the dashboard. To install the Dashboard, execute the below command

$ kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml


Step 6 : Your dashboard is now ready with it’s the pod in the running state.


Step 7 : By default dashboard will not be visible on the Master. Execute the below command

$ kubectl proxy


To view the dashboard in the browser, navigate to the following address in the browser of your Master


The below will be displayed on the webpage, to enter the credentials

Screenshot from 2018-09-27 17-08-32

Next we will create the service account for the dashboard and get it’s credentials. Open a new terminal and execute the below commands, or your kubectl proxy command will stop.

Step 8 : To create a service account for dashboard in the default namespace, execute the below command

$ kubectl create serviceaccount dashboard -n default


Step 9 : To add the cluster binding rules to your dashboard account, execute the below command

$ kubectl create clusterrolebinding dashboard-admin -n default \
  --clusterrole=cluster-admin \


Step 10 : To obtain the token required for your dashboard login, execute the below command

$ kubectl get secret $(kubectl get serviceaccount dashboard -o jsonpath="{.secrets[0].name}") -o jsonpath="{.data.token}" | base64 --decode


Step 11 : Copy the above token and paste in the dashboard page, by selecting Token option and signin to login.

Screenshot from 2018-09-27 17-11-27

Now you have successfully logged in to dashboard.

Screenshot from 2018-09-27 17-12-16

Steps For Only Kubernetes Node

Now we are goining the join the node to the cluster. We have run the join command that we have saved, when we execute ‘kubeadm init’ command on the master.

Execute the below command to join the node.


Screenshot from 2018-09-27 17-20-49

Now the kubernetes cluster is ready.