How to install Kubernetes on Ubuntu 20.04 🀯

How to install Kubernetes on Ubuntu 20.04 🀯

Β·

3 min read

Canonical, the publisher of Ubuntu, today announced the general availability of Ubuntu 20.04 LTS, with a particular emphasis on security and performance - April 23rd 2020

Kubernetes is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. It provides a way to manage and coordinate large numbers of containers across multiple hosts, and it abstracts away the underlying infrastructure to simplify management of the applications.

Ubuntu is a popular Linux distribution that is known for its ease of use and robust security features. It is commonly used for cloud computing and is well-suited for running containerized applications.

In this guide, we’re going to deploy a Kubernetes cluster consisting of nodes,which are running Ubuntu 20.04 πŸŒ•πŸš€.

Get Started

here are the steps to install Kubernetes on Ubuntu 20.04:

Step 1: Update the system Before installing Kubernetes on Ubuntu 20.04, it's recommended to update the system by running the following commands:

sudo apt update
sudo apt upgrade

Step 2: Install Docker Kubernetes requires a container runtime to manage the containers that run on each node in the cluster. Docker is a popular choice, and can be installed with the following command:

sudo apt install docker.io

After installation, check the status of Docker:

sudo systemctl status docker

Step 3: Disable swap Kubernetes requires swap to be disabled. To disable swap, run the following command:

sudo swapoff -a

Step 4: Install kubeadm, kubelet, and kubectl These are the Kubernetes components that you will use to create and manage your cluster. Run the following commands to install them:

sudo apt-get update && sudo apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl

After installation, check the status of kubelet:

sudo systemctl status kubelet

Step 5: Initialize the cluster To initialize the cluster, run the following command on the master node:

sudo kubeadm init --pod-network-cidr=192.168.0.0/16

This command initializes the control plane and creates a unique certificate for the master node. Note the kubeadm join command that is generated at the end of the initialization process. You will need this command to add worker nodes to the cluster.

Step 6: Set up the Kubernetes configuration file To set up the Kubernetes configuration file, run the following commands:

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

This command copies the configuration file for the cluster to the appropriate directory and sets the ownership and permissions for the file.

Step 7: Install a network plugin To enable communication between the nodes in the cluster, you will need to install a network plugin. One popular option is Flannel, which can be installed with the following command:

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

After installation, check the status of the pods:

kubectl get pods --all-namespaces

Step 8: Join worker nodes to the cluster To join a worker node to the cluster, run the kubeadm join command that was generated during the initialization process on the master node. For example:

sudo kubeadm join <master-node-ip>:6443 --token <token> --discovery-token-ca-cert-hash <hash>

Once the worker node is joined, it will be visible in the output of the following command on the master node:

kubectl get nodes

Congratulations! You have now installed and set up a Kubernetes cluster on Ubuntu 20.04.

Thanks for reading

Β