How To Install Kubernetes on Ubuntu 20.04 LTS

Install Kubernetes on Ubuntu 20.04

In this tutorial, we will show you how to install Kubernetes on Ubuntu 20.04 LTS. For those of you who didn’t know, Kubernetes is a free and open-source container management system that provides a platform for deployment automation, scaling, and operations of application containers across clusters of host computers. With Kubernetes, you can freely make use of the hybrid,on-premise, and public cloud infrastructure in order to run the deployment tasks of your organization.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of Kubernetes on a Ubuntu 20.04 (Focal Fossa) server. You can follow the same instructions for Ubuntu 18.04, 16.04, and any other Debian-based distribution like Linux Mint.


  • A server running one of the following operating systems: Ubuntu 20.04, 18.04, and any other Debian-based distribution like Linux Mint.
  • It’s recommended that you use a fresh OS install to prevent any potential issues
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, you can harm your system if you’re not careful when acting as the root.

Install Kubernetes on Ubuntu 20.04 LTS Focal Fossa

Step 1. First, make sure that all your system packages are up-to-date by running the following apt commands in the terminal.

sudo apt update
sudo apt upgrade
sudo apt install apt-transport-https curl

Step 2. Installing Docker.

Follow the command to install Docker CE on Ubuntu 20.04:

sudo apt install

Once the Docker is installed ensure that it is enabled to start after reboot:

sudo systemctl enable docker
sudo systemctl start docker

You can verify the Docker installation:

docker --version

Step 3. Installing Kubernetes on Ubuntu 20.04.

Now we add the Kubernetes signing key:

curl -s | sudo apt-key add

Next, we’ll add the Kubernetes package repository:

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

After that, run the following command to install Kubernetes:

sudo apt install kubeadm kubelet kubectl kubernetes-cni

Step 4. Disable swap memory.

Running Kubernetes requires that you disable swap:

sudo swapoff -a

To permanently disable swap, comment out or remove the swap line on /etc/fstab file:

sudo nano /etc/fstab
# / was on /dev/sda2 during curtin installation
/dev/disk/by-uuid/f3d575c6-e46go-4472-b406-30dmeilana965a / ext4 defaults 0 0
#/swap.img      none    swap    sw      0       0

Step 5. Set hostnames.

Now give hostnames to each node. In our scenario, we’re using the hostnames master-node and master-node to easily differentiate our hosts and identify their roles:

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

Step 6. Initialize Kubernetes master server.

First, enter the following command on your master node:

sudo kubeadm init

Next, run those three commands on the master node:

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

Step 7. Deploy a pod network.

The next step is to deploy a pod network. Run the following two commands on the master node:

kubectl apply -f
kubectl apply -f

You can use the kubectl command to confirm that everything is up and ready:

kubectl get pods --all-namespaces

Step 8. Join the Kubernetes cluster.

Now our cluster is ready to have the worker nodes join. Use the kubeadm join command retrieved earlier from the Kubernetes master node initialization output to join your Kubernetes cluster:

sudo kubeadm join --token 1exb8s.2t4k3bramnoamo --discovery-token-ca-cert-hash sha256:72gama4918cf2cute19356c9a402fb609263adad48c13797d0cba2341

Confirm that master-node is now part of our Kubernetes cluster with this command:

kubectl get nodes

Step 9. Deploying a service on the Kubernetes cluster.

In these steps, we are ready to deploy a service into the Kubernetes cluster. Run the following two commands on your master node:

kubectl run --image=nginx nginx-server --port=80 --env="YOUR-DOMAIN=cluster"
kubectl expose deployment nginx-server --port=80 --name=nginx-http

You should now see a new Nginx docker container deployed on your worker node:

sudo docker ps

Finally, you can see a running list of all available services running in your cluster with the following command, issued from the Kubernetes master node:

kubectl get svc

Congratulations! You have successfully installed Kubernetes. Thanks for using this tutorial for installing Kubernetes on Ubuntu 20.04 LTS Focal Fossa systems. For additional help or useful information, we recommend you to check the official Kubernetes website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!
Back to top button