Table of Contents
Kubernetes is an open-source project that allows you to deploy and manage multi-container applications at scale. Docker is the containerization framework that is used mainly with Kubernetes. But it is not limited to that. Kubernetes can be used with other container systems as well. As Docker is mostly used, we will also see how to install it in Ubuntu. We will learn how to install Kubernetes on Ubuntu 20.04 later in this article.
Note: If you are using CentOS, then refer to our article Install Kubernetes on CentOS 8.
- 2 or more Linux servers running Ubuntu 20.04 because the Kubernetes cluster has master-slave architecture where there can be multiple masters and multiple slaves.
- Access to a user account on each system with sudo or root privileges.
- It is recommended that each of your nodes have at least 2 CPUs and 2 gigabytes of RAM as this results in better performance. This is not a compulsory rule but if your application requires high resources, then you need to have this configuration.
- All of your nodes should be able to communicate with one another, using either a private or public network, depending on what is available because we need to connect the master machine(s) to the slave(s).
Install Docker on Ubuntu 20.04
Before installing Kubernetes, we have to install Docker. Docker is a container system that is used to create containers (you can say VMs) that are used to run the applications. Follow the below steps to install Docker in Ubuntu.
Execute the below mentioned commands on both worker and master nodes
1. Switch to root user and disable swap memory
sudo su swapoff -a
2. Update the packages
apt update -y
3. Install Docker
apt install -y docker.io
4. Check Docker version
5. Set Docker to launch at boot
systemctl enable docker
6. Start Docker
systemctl start docker
7. Check Docker status
systemctl status docker
Note: Press q to come out of status screen
We have successfully installed Docker. Now, we can proceed with installing Kubernetes.
Install Kubernetes on Ubuntu 20.04
Execute the below commands on both master and worker nodes
1. Execute the below command to add a signing key
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add
2. Add Kubernetes repository
apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
3. Install Kubernetes
apt install kubeadm kubelet kubectl -y
4. Verify the installation
Kubernetes have been installed on both nodes. Now you need to initialize a Kubernetes cluster on the Master node and add the worker node to it.
5. Execute the below command only on the Master node
kubeadm init --apiserver-advertise-address=10.128.0.6 --pod-network-cidr=192.168.0.0/16
In the above command, change the –apiserver-advertise-address IP address as per your instance. The IP address should be the private IP of your instance. In my case, the private IP is 10.128.0.6
As you can see from the above screenshot, the kubeadm init command has generated a kubeadm join command. Make a note of this command as we need to execute it in the worker node.
6. Execute the below commands in the Master node,
exit mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
7. Deploy a POD network to the cluster. A Pod Network is a way for nodes in a cluster to communicate with one another. Here, we’re using a flannel network. Execute the below command in the Master node,
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
8. Now execute the kubeadm join command that you noted down earlier in the Worker node from the root user,
kubeadm join 10.128.0.6:6443 --token pri513.injmsoqysq7dpcul \ --discovery-token-ca-cert-hash sha256:76404e055edd2ecd93a3490a6664aa03178dafd9dbf0003037f857d6639f7352
9. Execute the below command in the Master node to check the node status
kubectl get nodes
Done. We have successfully installed Kubernetes on our Ubuntu system.
Note: If the nodes are not in READY state, then wait for some time and execute the kubectl get nodes command again.