How to Install Kubernetes on Ubuntu 18.04

Open-source platform Kubernetes allows declarative configuration and automation of containerized workloads and services. An ecosystem of great size and rapid growth resides there. Several Kubernetes tools, services, and support options are available.Kubernetes derives its name from Greek, meaning pilot or helmsman. As an abbreviation, K8S is derived from the eight letters that lie between the “K” and the “s”.

In this tutorial, we will show you how to install Kubernetes on Ubuntu 18.04.  


Step 1: Install Docker
Docker must already be installed for Kubernetes to work. Go straight to Step 2 if you already have Docker installed.
To install Kubernetes, follow these steps:
Run the following command to update the package list:

# sudo apt-get update



Run the following command to install Docker:




sudo apt-get install


Similarly, repeat the process on each server acting as a node.




Enter the following to check the installation.




# docker ––version







Step 2: Install Kubernetes







Docker should be enabled on both nodes







By entering the following, Docker will be launched at boot:



# sudo systemctl enable docker


Make sure Docker is running:





# sudo systemctl status docker


If Docker isn’t running, you need to start it: 




# sudo systemctl start docker


Then repeat the process on all the other nodes.







Step 3: Add Kubernetes Signing Key





You can get the Kubernetes signing key by running the following command:




# curl -s | sudo apt-key add


You can install curl if you receive an error that it is not installed by following step:

# sudo apt-get install curl




Install the signing keys by repeating the previous command. Perform the procedure on every server node.





Step 4: Add Xenial Kubernetes Repository on both the nodes



Kubernetes is not included in the default repositories. To add them, enter the following:



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



Repeat on each server node.






Step 5: Install Kubeadm







Install Kubernetes tools on both the nodes through the following command:




# sudo apt-get install kubeadm kubelet kubectl

# sudo apt-mark hold kubeadm kubelet kubectl


Verify the installation with:




kubeadm version


Repeat for each server node.







Step 6: Begin Kubernetes Deployment






Disable the swap memory on each server


# sudo swapoff –a


Give Unique hostnames to each node(Master)


# sudo hostnamectl set-hostname master-node



On worker node,



# sudo hostnamectl set-hostname worker01



Use this process to set hostname for eack node.




Initialize Kubernetes on the master node





On master server node enter the following:



# sudo kubeadm init --pod-network-cidr=



The process will take a minute. Once it finishes, kubeadm join message will display at the end. Make a note of the whole entry. This will be used to join the worker nodes to the cluster.



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 7: Deploy Pod Network






Enter the following:


# sudo kubectl apply -f




Verify all the thing.



# kubectl get pods --all-namespaces
Join Worker Node to Cluster


As we mentioned before you can enter the kubeadm join command on each worker node to do it. For this switch to worker node and run the following


# kubeadm join --discovery-token abcdef.1234567890abcdef --discovery-token-ca-cert-hash sha256:1234..cdef

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.

On master server enter the following:

kubectl get nodes

Now you will see the worker node in the system that you joined to the cluster and you should now have Kubernetes installed on your Ubuntu 18.04 instance.

Thank you for reading.

Try VPSie for free today!