Contents
1. What is Kubernetes
kubernetes (commonly stylized as k8s) is an open-source system for automating deployment, scaling, and management of containerized applications.
k8s : technology developed in Google lab in 2005 to manage containerized applications in different kind of environments such as physical, virtual, and cloud infrastructure.
2. Adience
This article is prepared for anyone who want to understand the containerized infrastructure and deployment of application on containers using kubernetes. and will help you to understand the concepts of container management using this technology.
3.Prerequisites
- An SSH key pair on your local Linux/Mac OS/BSD machine.
- Three servers running Ubuntu 19.04 with at least 2GB RAM and 2 vCPUs each.
4.Kubernetes Installation
In this article we will use two servers to setting up kubernetes cluster, the first server is considered as master and the second as slave
Both these nodes need to have Kubernetes and docker installed. Therefore, to install kubernetes on both the Ubuntu nodes follow the steps described below:
Step 1 : Install Docker master and slave nodes
Install Docker utility on both the nodes by running the following command as root user (use sudo) in the Terminal of each node:
1 |
sudo apt install docker.io |

You can verify the installation and also check the version number of Docker through the following command:
1 |
docker --version |

Step 2: Enable Docker in master and slave nodes
Enable the Docker utility on both the nodes by running the following command on each:
1 |
sudo systemctl enable docker |

Step 3: Add the Kubernetes signing key on both the nodes
Run the following command in order to get the Kubernetes signing key:
1 |
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add |

If Curl is not installed on your system, you can install it through the following command as root:
1 |
sudo apt install curl |
Step 4: Add Xenial Kubernetes Repository on both the nodes
Run the following command on both the nodes in order to add the Xenial Kubernetes repository:
1 |
sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main" |

Step 5: Install Kubeadm
kubeadm helps you bootstrap a minimum viable Kubernetes cluster that conforms to best practices. With kubeadm, your cluster should pass Kubernetes Conformance tests. Kubeadm also supports other cluster lifecycle functions, such as upgrades, downgrade, and managing bootstrap tokens.
The final step in the installation process is to install Kubeadm on both the nodes through the following command:
1 |
sudo apt install kubeadm |

You can check the version number of Kubeadm and also verify the installation through the following command:
1 |
kubeadm version |

5. Kubernetes Deployment
Step 1: Disable swap memory (if running) in master and slave nodes
You need to disable swap memory in master/slaves nodes as kubernetes does not perform properly on a system that is using swap memory.
To disable swap memory you can run the following command :
1 |
sudo swapoff -a |

Step 2: Give Unique hostnames to master and slave nodes
Run the following command in the master node:
1 |
sudo hostnamectl set-hostname master-node-k8s |
Run the following command in the slave node:
1 |
hostnamectl set-hostname slave-node-k8s |
Step3: Initialize Kubernetes on the master node
Run the following command as sudo on the master node:
1 |
sudo kubeadm init --pod-network-cidr=10.244.0.0/16 |
The process might take a minute and the output of this command is very important:

To start using your cluster, you need to run the following as a regular user:
1 |
mkdir -p $HOME/.kube<br>sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config<br>sudo chown $(id -u):$(id -g) $HOME/.kube/config |

You can check the status of the master node by running the following command:
1 |
kubectl get node |

Firstly, you will see that the status of the master node is “not ready” yet. It is because no pod has yet been deployed on the master node and thus the Container Networking Interface is empty.
Then you can join any number of worker nodes by running the following on each as root:
1 |
kubeadm join 192.168.43.59:6443 --token vphcvu.bezen1rxiwsmyfg0 --discovery-token-ca-cert-hash sha256:476f497c72ce84839d4edbed0dd0a613b073371c3578e6dbbd03d8b59fdfb151 |
Step 4: Deploy a Pod Network through the master node
A pod network is a medium of communication between the nodes of a network. In my case i use Flannel pod network:
flannel is a virtual network that gives a subnet to each host for use with container runtimes.
1 |
sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml |

Use the following command in order to view the status of the network:
1 |
sudo kubectl get pods --all-namespaces |

After deploying flannel pod network Now when you see the status of the nodes, you will see that the master-node is ready:
1 |
sudo kubectl get nodes |

Step 5: Add the slave node to the network in order to form a cluster
Now we have master node is up and cluster is ready and configued, we can add slaves nodes to cluster.
On the slave node you can run the following command you generated while initializing Kubernetes on the master-node-k8s (Step3: Initialize Kubernetes on the master node):
1 |
kubeadm join 192.168.43.59:6443 --token vphcvu.bezen1rxiwsmyfg0 --discovery-token-ca-cert-hash sha256:476f497c72ce84839d4edbed0dd0a613b073371c3578e6dbbd03d8b59fdfb151 |
After adding first slave node to cluster you can see a second node in cluster nodes list, to verify that you run the following command on the master node, it will confirm that two nodes, the master node, and the server nodes are running on your cluster kubernetes :
1 |
sudo kubectl get nodes |
6. Conclusion
In this post, i have explained the installation of the Kubernetes cluster on two Ubuntu nodes.
If you have any questions or feedback, feel free to leave a comment.
As always, if you found this post useful, then click like and share it 🙂
Leave a Reply