In this article, we will have explained the necessary steps to install and configure Kubernetes on Ubuntu 20.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with
sudo privileges. All the commands in this tutorial should be run as a non-root user.
Kubernetes is an open-source platform for managing container technologies such as Docker. With Kubernetes, you can freely make use of the hybrid, on-premise, and public cloud infrastructure in order to run deployment tasks of your organization.
Install Kubernetes on Ubuntu 20.04
Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.
sudo apt update sudo apt upgrade sudo apt install apt-transport-https curl
Step 2. Install Docker.
Kubernetes requires an existing Docker installation, run the following commands to install Docker:
sudo apt install docker.io
Once Docker has finished installing, use the following commands to start the service and to make sure it starts automatically after each reboot:
sudo systemctl start docker sudo systemctl enable docker
Step 3. Install Kubernetes on the Ubuntu system.
Add the Kubernetes signing key to both systems:
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add
Kubernetes is not included in the default repositories. To add them, enter the following:
sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
Now we can install Kubernetes:
sudo apt install kubeadm kubelet kubectl kubernetes-cni
Step 4. Disable swap memory.
Running Kubernetes requires that you disable swap. Before proceeding further, make sure that the master and worker node have swap memory disabled:
sudo sed -i '/ swap / s/^\(.*\)$/#/g' /etc/fstab sudo swapoff -a
Step 5. Set hostnames.
Assign Unique Hostname for Each Server Node:
sudo hostnamectl set-hostname kubernetes-master
Next, set a worker node hostname by entering the following on the worker server:
sudo hostnamectl set-hostname kubernetes-worker
Step 6. Initialize the Kubernetes master server.
Run the following command on your master node:
sudo kubeadm init
Step 7. Deploy a pod network.
The next step is to deploy a pod network. The pod network is used for communication between hosts and is necessary for the Kubernetes cluster to function properly:
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/k8s-manifests/kube-flannel-rbac.yml
Verify that everything is running and communicating:
kubectl get pods --all-namespaces
Step 8. Join the Worker Node to Cluster.
You can now add other nodes to the Kubernetes cluster using the
kubeadm join command as follows.
kubeadm join --discovery-token abcdef.1234567890abcdef --discovery-token-ca-cert-hash sha256:1234..meilana 18.104.22.168:6443
Back on your Kubernetes master node, confirm that
kubernetes-worker is now part of our Kubernetes cluster with this command:
kubectl get nodes
Step 9. Deploying a service on the Kubernetes cluster.
Now we ready to deploy a service into the Kubernetes cluster. In our example, we will deploy an Nginx server into our new cluster as a proof of concept:
kubectl run --image=nginx nginx-server --port=80 --env="DOMAIN=cluster" kubectl expose deployment nginx-server --port=80 --name=nginx-http
That’s all you need to do to install Kubernetes on Ubuntu 20.04 LTS Focal Fossa. I hope you find this quick tip helpful. If you have questions or suggestions, feel free to leave a comment below.