How To Install And Configure Kubernetes On Ubuntu

In this blog post , We have explained how to install and configure kubernetes on ubuntu.

In this blog post , We will see how to setup kubernetes master slave architecture from the scratch.

What Is Kubernetes?

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

We can build an docker images and we can run containers out of it using Docker engine.

And kubernetes will help in managing those containers by loadbalancing and scaling between the containers.


For setting up Master Slave kubernetes architecture , We need,

  • Minimum 2 or more Ubuntu operating systems.
  • You should have access to the servers with sudo or root privileges

In this tutorial , We will learn to setup 1 Master node and 1 Worker node setup.

The first step is to install docker on all the servers of the kubernetes nodes.

Installing Docker

Kubernetes requires Docker to be installed on all the ubuntu servers.

If you have already installed docker on all the system , You can ignore this this , If not , Check this article , To install Docker on Ubuntu servers.

Once the docker is installed , Make sure the docker service is UP and running on master and worker nodes using the below command.

sudo systemctl status docker

Lets go ahead and install kubernetes on the nodes.

Installing Kubernetes

In this step We are going to install tools such as kubeadm , kubelet and kubectl.

The following steps should be executed on all the servers.

If curl package is not installed , Install it using ,

apt-get install curl

Then We need to add a signing key using the command.

curl -s | sudo apt-key add

Then we need to add kubernetes software package repository to the system as they are not included in the default system repositories.

sudo apt-add-repository "deb kubernetes-xenial main"

Installing Kubernetes Tools

Here we are going to install tools such as kubeadm , kubelet and kubectl.

kubeadm is a tool which helps you to install and set up a Kubernetes cluster.

kubelet is the node agent that runs on each node which helps to start containers and registere the node with the api server.

kubectl is a command line tool using which you can control kubernetes cluster.

Install the above packages using the below command.

apt-get install kubeadm kubelet kubectl -y
sudo apt-mark hold kubelet kubeadm kubectl

Lets check the version of kubernetes tools installed on the servers and also make sure to maintain same versions on all the servers.

kubelet --version
kubeadm version
kubectl version

Before initializing kubernetes on master nodes we need to setup proper hostname on all the servers and disable swap on all the servers using the below commands.

hostnamectl set-hostname master-node
hostnamectl set-hostname slave-node

If you have multiple slave nodes , Setup hostnames accordingly.

Then disable swap using the command,

sudo swapoff -a

Initializing Kubernetes On Master Node

Login to master node and enter the below command to initialize kubernetes.

kubeadm init --pod-network-cidr=

And while running the above command you may get the below error.

Make sure the servers has minimum of 2 vCPU to successfully initialize the kubernetes.

If the above command is successful , At the end , It will display kubeadm join message at the end.

Make a note of the entire line (command).Using will we will join the worker nodes with the master node.

To start using the cluster , We need to setup folders for the kubernetes cluster.

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

Then we need to deploy pod network to the cluster.

Pod network is a way to make communications between the nodes in the cluster.

Lets deploy a Flannel virtual network into the cluster using the below command.

sudo kubectl apply -f

The Flannel pod network will be delpoyed into the kube-system namespace.

To list all the pods running across the namespaces , Run the below command.

kubectl get pods --all-namespaces

Some of the useful commands as follows.

To list all the namespaces in the cluster

kubectl get ns

To list the nodes in the cluster

kubectl get nodes

You can see only the master node within the cluster.As we havn’t joined the worker nodes within the cluster yet.

Lets go ahead and join the worker nodes to the cluster.

Joining Worker Nodes To The Cluster

To join worker nodes with the within the cluster , We need the kubeadm join command , Which we got while initializing the cluster in the master node.

Now Login to worker nodes and run the kubeadm join command.

kubeadm join --token 2txg2t.mb2fi46jhd837wev --discovery-token-ca-cert-hash sha256:ce920cea8732eeab34dac71411e75acb56782hss7250281687934ac9644977e26

Don’t forget to replace –token and –discovery-token-ca-cert-hash with your value.

Note: Make sure the worker nodes are able to reach port 6443 on the master node. Check the firewall.

Once the command is successfully executed , You should get the below response.

From the above image , You can see that the worker node is successfully joined with the kubernetes cluster.

Now Login to Master node and run the below command,

kubectl get no

You can see that the worker node is successfully joined to the cluster.


We have successfully installed and configured kubernetes cluster on ubuntu.

Thanks for reading , Please do check out my other blogs.