How to install Kubernetes on Ubuntu 18.04 LTS

Filed Under: Ubuntu

Kubernetes also referred to as k8 , is a free and opensource tool used for management of Docker containers. It’s a container orchestration platform that is tailored to automate the deployment, scaling, and management of containerized applications. In this guide, you will learn how to install and configure Kubernetes on Ubuntu 18.04 LTS.


Before we get started , we are going to have a test lab comprising 3 Ubuntu 18.04 nodes as shown below

  1. Kubernetes Master Node IP address: Hostname: k8-master
  2. Kubernetes Slave Node 1 IP address: Hostname: k8-slave
  3. Kubernetes Slave Node 2 IP address: Hostname: k8-slave2

In addition, ensure that your system has the following minimum requirements.

  1. 2 CPUS
  2. 4 GB RAM
  3. 8 GB free Hard disk space

Let’s now dive in and get started.

Step 1. Setting up hostname & Updating hosts file

To start off, you are going to log in the Master Node via SSH and set up the hostname as shown

$ sudo hostnamectl set-hostname "k8-master"

On the slave nodes run the following commands

$ sudo hostnamectl set-hostname k8-slave
$ sudo hostnamectl set-hostname k8-slave2

Using your favorite text editor, make the following modifications in the /etc/hosts file for each of the 3 Nodes i.e k8-master, k8-slave and k9-slave2 respectively.     k8s-master    k8-slave    k8-slave2

Step 2. Installing Docker on Master and Slave Nodes

To install docker on the Master node, first, update and upgrade the system using the command below

$ sudo apt-get update && sudo apt-get upgrade

Next, install Docker both on the Master and Slave nodes using the following command

$ sudo apt-get install -y


Install and configure kubernetes and  Docker on Ubuntu 18.04

Once Docker is successfully installed, start and enable Docker service on both the Master and slave nodes using the commands below.

$ sudo systemctl start docker
$ sudo systemctl enable docker


Start And Enable Docker Service

To verify that docker is running, issue the command on the master and slave Nodes

$ sudo systemctl status docker


Check Docker Status

To view the Docker version that you’ve just installed run

$ docker --version


Check Docker Version

Step 3. Configuring Kubernetes repository on Master & Slave nodes

Before going to the next step, We need to install some useful packages. run the following commands on all the nodes

$ sudo apt-get install apt-transport-https curl -y


Install Required Packages

Next, add the Kubernetes package repository key by executing the command below

$ curl -s | sudo apt-key add


Add Kubernetes Package Repo Key

Next, add the Kubernetes repository using the command below.

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


Configure Kubernetes Repository


Kubernetes package repository for Ubuntu 18.04 LTS is not available. Nevertheless, We have used the Xenial Kubernetes package repository.

Step 4. Disabling swap and installing kubeadm

We are going to install kubeadm package to allow us to deploy multiple nodes on our cluster.

But before we do so, Kubernetes Offical site recommends disabling the OS swap feature. To accomplish this run the following command.

$ sudo swapoff -a

you can now install the kubeadm package as follows.

$ sudo apt-get install kubeadm -y


Install Kubeadm Package

Upon successful installation of kubeadm package, verify its version using the command below

$ kubeadm version


Check Kubeadm Version

Step 5. Starting Kubernetes Cluster using Kubeadm

On the Master node, log in and initialize kubernetes using kubeadm as shown.

$ sudo kubeadm init --pod-network-cidr=

Sample output

Kubernetes Master Successfully Initiated

The output above is a confirmation that we have successfully initiated the Kubernetes Master node To start the cluster, execute the commands enclosed inside the green highlight, one after the other

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

Now we are going to verify the status of the Master node by running the command below.

$ kubectl get nodes

At this point, you will get a prompt that the Master Node is not ready because we have not yet deployed any pod. In the next step, we are going to deploy a pod network which is the network that our cluster nodes will be able to communicate with each other. To accomplish this, we are going to deploy Flannel as our pod network. Flannel is going to provide an overlay network between cluster nodes

Step 6. Deploying Flannel as the pod network

To deploy the pod network, run the following command in the Master node

$ sudo kubectl apply -f

Sample output

Deploy Pod Network

At this point, we can now verify the status of the Master Node using the kubectl command

$ sudo kubectl get nodes


Master Node Ready

As seen above, the Master node status has changed to “Ready’. In addition, verify the pod namespaces as shown.

$ sudo kubectl get pods --all-namespaces


Get Pods All Namespaces

The output above shows that all the pod namespaces are in a running state. the final step will be joining the slave nodes to the cluster.

Step 7. Adding Slave node to the cluster

In this step, we are going to log in to both slave nodes (k8-slave and k8-slave2) and execute the following command which appears hightlighted in red in Step 5

Command To Be Run On Each Node

$ kubeadm join --token w8kbni.wiyevyov0yxwwtdj --discovery-token-ca-cert-hash sha256:29adc042c538f59f0c7339ebad2126d5836de06ffe0ae22c54ce0aef2eb4cb76

Sample output

Successfully Joined Node

Now head out to the Master slave and check the status of the master and slave nodes using the kubectl command

$ kubectl get nodes


kubectl get nodes

The output above confirms that we have successfully added our two slave nodes to the cluster and their status, as well as the Master node, is ready!

Wonderful! We have concluded our tutorial on how to install and configure Kubernetes on Ubuntu 18.04 LTS. Your feedback is most welcome.


  1. vinodkumar says:

    Hello Punkaj

    Thanks for your eazy installation guide. i was able to install it.


  2. Oscar Gemperle says:

    Hello Pankaj

    I followed your tutorial and I was able to create a cluster.
    But after I restart the VMs, I cannot start the cluster again.
    I could restart the master after these steps:
    kubectl reset
    rm -rf /var/lib/etcd/
    kubectl init
    I could join the slaves again.
    But when I try to execute sudo kubectl get pods –all-namespaces or sudo kubectl get nodes, I get this error:
    Unable to connect to the server: x509: certificate signed by unknown authority (possibly because of “crypto/rsa: verification error” while trying to verify candidate authority certificate “kubernetes”)

    What is the problem?

  3. rajani says:

    Nice Posting !! Thanks for sharing..

Comments are closed.

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors