How To Install Kubernetes On Ubuntu 20.04 – Kubeadm And Minikube

Reading Time: 2 minutes

In this article, we will see how to install Kubernetes on ubuntu 20.04. Over the past few years, containerization has provided a lot of flexibility to the developers. One of the most commonly used applications for containerization is Docker. Container provide the developer a virtual environment and isolation for our applications on the host system. However, there were a few problems with it.

Running small applications is not that difficult but what if you want to scale them? When you have hundreds or thousands of servers, scaling isn’t that easy. There should be an automation tool that will take full responsibility for allocating resources to our application on specific machines, and not only this, continuous monitoring and resilience are also required.

One of the main reasons for deploying a service on a container is that they are flexible, lightweight, and easily scalable while deploying on hundreds of machines. But, who is going to manage all these containers? This is where Kubernetes comes into the picture.

What Is Kubernetes?

Kubernetes (also referred to as “K8″) is an open-source project by Google for managing the containerized application on the cluster by providing services such as scaling, deployment, and maintenance. If you want to know more about Kubernetes and its architecture in detail then click here.

kubernetes architecture

Kubernetes is currently the market leader and beats its competitors such as Docker Swarm and Apache Mesos in most scenarios. However, one big disadvantage of Kubernetes is its difficulty in setting up. Some cloud vendors do provide pre-made clusters for you to use but they are paid. What to do when you just want to learn Kubernetes and that too for free?

Let us see how we can run a Kubernetes Cluster on Ubuntu 20.04.

Kubernetes Installation – Using kubeadm

First, have two VM’s setup. One of which we will be using as our master node, and other as worker node.

  1. Install Docker
$ sudo apt update
$ sudo apt install
$ sudo systemctl start docker
$ sudo systemctl enable docker
  1. Install Kubernetes
$ sudo apt install apt-transport-https curl
$ curl -s | sudo apt-key add
$ sudo apt-add-repository "deb kubernetes-xenial main"
$ sudo apt install kubeadm kubelet kubectl kubernetes-cni
  1. Disable Swap Memory
$ sudo swapoff -a
$ sudo nano /etc/fstab

Inside this file, comment out the /swapfile line.

  1. Set hostnames
$ sudo hostnamectl set-hostname kubernetes-master
$ sudo hostnamectl set-hostname kubernetes-worker
  1. Initialize Kubernetes master server

Run these on the master node:

kubernetes-master:~$ sudo kubeadm init
kubernetes-master:~$ mkdir -p $HOME/.kube
kubernetes-master:~$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
kubernetes-master:~$ sudo chown $(id -u):$(id -g) $HOME/.kube/config
  1. Deploy a pod network
kubernetes-master:~$ kubectl apply -f
kubernetes-master:~$ kubectl apply -f
kubernetes-master:~$ kubectl get pods --all-namespaces
  1. Join the Kubernetes cluster

Run these from the worker node:

kubernetes-worker:~$ sudo kubeadm join --token 1exb8s.2t4k3b5syfc3jfmo --discovery-token-ca-cert-hash sha256:72ad481cee4918cf2314738419356c9a402fb609263adad48c13797d0cba2341
kubernetes-master:~$ kubectl get nodes

Kubernetes Installation – Using minikube (Locally)

For this demo, we are going to use an application called minikube. Open a terminal using Ctrl + Alt + T and enter the following commands:

curl -LO
sudo install minikube-linux-amd64 /usr/local/bin/minikube
minikube start

This will start a Kubernetes Cluster locally. To stop the cluster, you can:

minikube stop

To access your local Kubernetes’ dashboard:

minikube dashboard

Written by 

Mohit Saxena is a Software Consultant having experience of more than 2 years. He is always up for new challenges and loves to aggressively move towards completing the software requirements. On a personal front, he loves to climb mountains and is a big foodie.