Installing & Configuring “Kubernetes” Cluster on Ubuntu-18.04 LTS hosts

Vishal Sharma
4 min readSep 3, 2019

--

Kubernetes Cluster

Kubernetes is a free and open-source container orchestration system that facilitates deployment automation, scaling, and operations of containers across clusters. With Kubernetes, we can make use of the hybrid,on-premise, and public cloud infrastructure in-order to run deployment tasks of your organization.

In this tutorial, we will install and configure the 2-nodes Kubernetes Cluster on a single master & slave nodes.

Prerequisites:

  • 2 Ubuntu 18.04 LTS Host Machines (I used 2 virtual machines).
  • Make sure both machines are reachable from each other.
  • Hostnames are configured properly on both machines (I used “Tony” & “Guy”).

Common Application to be installed on both machines:

$ sudo apt update
$ sudo apt install docker.io
$ sudo systemctl enable docker
$ sudo docker --version

apt install docker.io

Add the Kubernetes signing key on both the nodes

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add

Add signing key

Add Xenial Kubernetes Repository on both the nodes

$ sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"

Install Kubeadm

$ sudo apt install kubeadm

Checking Kubeadm version

$ kubeadm version

Kubeadm version

Note: Disable swap memory (if running) on both the nodes

$ sudo swapoff -a

To start using your cluster, you need to run (as a regular user):

$ sudo cp /etc/kubernetes/admin.conf $HOME/
$ sudo chown $(id -u):$(id -g) $HOME/admin.conf
$ export KUBECONFIG=$HOME/admin.conf

Initialize Kubernetes on the Master Node

Run the following command as sudo on the master node (Tony in my case):

$ sudo kubeadm init --pod-network-cidr=10.222.0.0/16

We will able to see the output like above. If not then, please check that all configurations are performed properly. Kubeadm will generate an initial token to join the slave nodes to the cluster.

We can check the status of the master node by the following command:

$ kubectl get nodes

kubectl get nodes

We will able to 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.

Add the slave node to the network in order to create a Cluster

On the Slave node (Guy in my case), run the following command we generated while initializing Kubernetes on the master-node:

$ sudo kubeadm join 10.00.00.00:6443 — token 7m27aq.1rvdswidl4hmlbt5 — discovery-token-ca-cert-hash sha256:6f8ba9d0c92007c0452eb105eae1a57052d99db5fb8dfab29ee603cc762aaefb

Joining the Cluster
Output on the Slave node

We will be able to see the output like this on the Slave node.

Checking the Nodes status

Checking the Slave node (Guy) status on the Master node (Tony)

$ kubectl get nodes

kubectl output

We will able to see that the status of both the nodes 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.

Deploy a Pod Network

A pod network is a communication medium between the nodes of a network, deploying a Flannel pod network on our cluster through the following command:

$ kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

$ kubectl get pods — all-namespaces

Get Pods Status

Running the get nodes command again to check the status

$ kubectl get nodes

kubeclt get nodes

This shows that the two-node cluster is now configured and running properly through the Kubernetes.

--

--

Vishal Sharma

IT Enthusiast, Professional, Novice Sportsperson and Fantasist of Better World. @byVishalSharma on Twitter.