In this article, we will have explained the necessary steps to install and configure Kubernetes on Ubuntu 18.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 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 deployment tasks of your organization.
Install Kubernetes on Ubuntu
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
Step 2. Install Docker.
Install Docker with the command:
sudo apt install docker.io
You can verify the installation and also check the version number of Docker through the following command:
docker --version
Enable the Docker utility on both the nodes by running the following command on each:
sudo systemctl enable docker sudo systemctl start docker
Step 2. Installing Kubernetes.
First, Add Kubernetes Signing Key:
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add
Next, Add Software Repositories:
sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
Kubeadm (Kubernetes Admin) is a tool that helps initialize a cluster. It fast-tracks setup by using community-sourced best practices. Kubelet is the work package, which runs on every node and starts containers. The tool gives you command-line access to clusters:
sudo apt-get install kubeadm kubelet kubectl sudo apt-mark hold kubeadm kubelet kubectl
Verify the installation with:
kubeadm version
Step 3. Kubernetes Deployment.
Begin Kubernetes Deployment, Start by disabling the swap memory on each server:
sudo swapoff –a
Assign Unique Hostname for Each Server Node:
sudo hostnamectl set-hostname master-node
Next, set a worker node hostname by entering the following on the worker server:
sudo hostnamectl set-hostname worker01
Step 4. Initialize Kubernetes on Master Node.
Switch to the master server node, and enter the following:
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
Once this command finishes, it will display a kubeadm join message at the end. Make a note of the whole entry. This will be used to join the worker nodes to the cluster. Then, enter the following to create a directory for the cluster:
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
Step 5. Deploy Pod Network to Cluster.
A Pod Network is a way to allow communication between different nodes in the cluster. This tutorial uses the flannel virtual network:
sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Verify that everything is running and communicating:
kubectl get pods --all-namespaces
Step 6. Join Worker Node to Cluster.
Switch to the worker01 system and enter the command you noted from Step 3:
kubeadm join --discovery-token abcdef.1234567890abcdef --discovery-token-ca-cert-hash sha256:1234..ramona 1.2.3.4:6443
Replace the alphanumeric codes with those from your master server. Repeat for each worker node on the cluster. Wait a few minutes. then you can check the status of the nodes and Switch to the master server, and enter:
kubectl get nodes
That’s all you need to do to install Kubernetes on Ubuntu 18.04 LTS. I hope you find this quick tip helpful. If you have questions or suggestions, feel free to leave a comment below.