Connect with us


How to Set up a 3 node Kubernetes cluster on Ubuntu 20.04

Colloquially known as k8s, Kubernetes is an open-source tool used for management of Docker containers. As a container orchestration platform, Kubernetes is programmed for the management, scaling, and deployment of containerized applications. With that in mind, we’ll touch base on how you can set up a 3 node Kubernetes cluster on Ubuntu 20.04 LTS.

Without much further ado, let’s roll our sleeves.

Lab setup

This will be our model setup for this tutorial:

Master node: – k8-master – IP:

Slave Node 1: k8-slave – IP:

Slave Node 2:k8-slave2 – IP:

For each of the nodes, ensure that they meet the following minimum prerequisites.

  1. 2 CPUs
  2. 8 GB of hard disk space
  3. 4 GB of RAM

Having looked at the basic requirements and the setup, let now see how you can configure a Kubernetes cluster on Ubuntu 20.04.

Step 1: Set up the hostname and update the host files

First off, you need to log in to each the Kubernetes nodes using ssh and set up the hostname as shown:

For the master node:

Slave 1 node:

Slave 2 node:

Additionally, update the /etc/hosts file for the 3 nodes as shown:

Let’s now jump right in and get started.

Step 1: Set up the hostname and update the host files

Right off the bat, log in to the Kubernetes Master Node and set up the master hostname as shown:

In the same vein, configure the hostname for the slave nodes by running the following commands:

Next, modify the /etc/hosts file for the 3 Kubernetes nodes as shown to reflect the hostname entries and IP addresses.

Step 2: Install Docker on the Master and Slave Nodes

Before installing Docker, you need to update the package repositories. To achieve this, execute the command:

Next, install docker by invoking the command:


Once you have successfully installed docker, start and enable the Docker service on your Master and the slave nodes as shown.


It’s prudent to verify that the docker service is running as expected by running the command on both the master and slave nodes.


This should display the status of your Docker service as depicted in the screenshot above.

Confirm the Docker version you’ve installed and run by invoking the command:


Step 3: Configure the Kubernetes repository on the Master and Slave nodes

Before you get started in configuring the Kubernetes repository on your nodes, a few dependencies are essential. Run the command below to install the requisite dependencies:

Thereafter, add Kubernetes GPG key as shown:

At the time of penning down this tutorial, there’s no Kubernetes package repository for Ubuntu 20.04 LTS and so we’ll use the repository for Ubuntu 16.04 – Xenial Xerus.

To append the repository run the command:


Step 4: Disable OS swap and install kubeadm

To deploy multiple nodes on your Kubernetes cluster, you’ll first need to install the kubeadm package. However, the official Kubernetes site recommends that you first disable the OS swap feature on all the nodes.

Therefore, to disable swap on both the master and slave nodes, execute the following command:

Proceed to install the kubeadm package following this command:


Once you have successfully installed the kubeadm package, feel free to verify its version as shown:


Step 5: Create your Kubernetes Cluster using Kubeadm

To fire up your cluster, log in and start Kubernetes on your system’s Master node using kubeadm as illustrated in the below:

Let’s dissect the command:

The --apiserver-advertise-address flag specifies the IP that the API server is listening on. If this is not specified, the default network interface will be assumed.

The --pod-network-cidr= flag specifies a IP address range foe the pod network, when set, CIDRs will automatically be allocated to every node. You should specify this is there’s conflict between the preferred pod network and some of the nodes in your LAN.

If the Kubernetes master node initializes successfully, you should see the output displayed below:

Take extra note of the last 2 lines at the bottom. This is the command that you will invoke at each of the ‘worker’ or slave nodes to join them to the Kubernetes cluster.

To initialize the Kubernetes cluster, execute the commands below one after the other as printed at the end of the output in the previous screenshot

You can now verify your Master node’s status by executing the command:


At this point, the system will notify you that the Master Node is not ready because no pod has been deployed so far… A pod network is the network infrastructure that enables your Kubernetes cluster nodes to communicate with each other. For this, you’ll need to supply an overlay network between all your Kubernetes cluster nodes. In this case, use Flannel as your pod network.

Step 6: Deploy Flannel as your pod network

On the master node, proceed and deploy the pod network. To do so, run the following command on the master node:

Once again, Verify the Master node’s status using the kubectl command. The status of the Master node should change from ‘NOT READY‘ to ‘READY’ as shown:

Proceed to verify the pod namespaces using the command:

confirm-that-pod-namespaces-are running-on-kubernetes-cluster-on-ubuntu

The output clearly confirms that all the pod namespaces are up and running.

Step 7: Add the Slave nodes to the Kubernetes cluster

This final step involves connecting the slave nodes to the Kubernetes cluster. To achieve this, you’ll need to log in to each of the slave nodes. Paste the command that we discussed earlier in step 5 to join the Kubernetes cluster.

If you didn’t save the command, you can run the following command at any given time to print out the joining command:

Here’s a sample output for the command:


Head over to the other slave node and execute the same command:


Now, head over to the master node and establish the status of both the master and slave nodes via the command:

Kubernetes cluster on Ubuntu

The output confirms the successful addition of your two slave nodes to the Kubernetes cluster on Ubuntu 20.04LTS. It also verifies the status of your master and slave nodes as ready. Perfect! This draws the curtains in the guide where we demonstrated adding 3 nodes on a Kubernetes cluster on Ubuntu 20.04LTS.

Continue Reading