How to install Kubernetes on Linux CentOS 8 / RHEL VPS, VDS, Server

Now that the New Linux CentOS 8 is taking the lead and many companies need to upgrade from CentOS 6 or CentOS 7. Then the best choice at the moment at beginning of 2021 is CentOS 8 since it has a long support time and security updates support. Based on all the before mentioned the Kubernetes have accordingly changed the installation of Kubernetes. let's have a look at how to install it. Just a reminder, that Kubernetes can also be installed on our hosted VPS/VDS servers

The things that you would need to prepare before Kubernetes installation are.

1. A running instance of CentOS 8
2. Docker CE installed and running
3. A user with Sudo privileges
4. Access to the root user


Now how to install Kubernetes

Remember, you must have Docker CE installed, before starting this process. Once you have the Docker engine up and running, how to add Kubernetes to the server.

The first thing to be done is the addition of the Kubernetes repository. To do this, open a terminal on the CentOS 8 server and issue the command:

sudo nano /etc/yum.repos.d/kubernetes.repo

In this new file, paste the following contents:


Save and close the file.

Now let's put a hostname and IP for DNS in the file

nano  /etc/hosts

Set SELinux policy to the Permissive

sudo setenforce 0
nano /etc/sysconfig/selinux

Disable the Swap

Finally, before you initialize your Kubernetes cluster, you must disable swap. For this, issue the command:

sudo swapoff -a

To make this permanent, issue the command:

nano /etc/fstab

Comment out the line that starts with /dev/mapper/cl-swap swap. Save and close the file.

Next, install the necessary packages with the command:

dnf install -y kubelet kubeadm kubectl - -disableexcludes=kubernetes

Enable the Kubelet daemon with the command:

 systemctl enable - -now kubelet

For the next task, you must su to the root user. Once you’ve done that, issue the command:

nano /etc/sysctl.d/k8s.conf

In this new file, add the following two lines:

net.bridge.bridge-nf-call-ip6tables = 1 
net.bridge.bridge-nf-call-iptables = 1

Save and close the file.

Let's start the services:

sudo systemctl restart kubelet
sudo systemctl enable kubelet
sudo systemctl status kubelet

After this, we need to initialize the kubeadm with the command.

kubeadm init

Once Kubernetes initialized successfully, you must enable your user to start using the cluster. You can also start the cluster using as shown.

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

You can now initialize your Kubernetes cluster and add nodes. Your CentOS 8 Kubernetes server is ready to start deploying.

Adding Worker Nodes to Kubernetes Cluster

You can follow the same steps starting from 1–3 i.e till( kubeadm, kubelet, and kubectl) on the worker nodes and once everything set up on the worker node.

you can generate tokens freshly by executing the command, on the master.

kubeadm token create — print-join-command

now copy the token and run that on the worker node

 kubeadm join — token 0xbszv.o9j5fim3j21xz47a \ — discovery-token-ca-cert-hash sha256:876637c5e5c74fcafa05372d187b58d36aa418b9faa46e1ec4c7388443143087

Go back to your master node and verify if worker k8worker has joined the cluster using the following command.

kubectl get nodes

If all the steps run successfully, then, you should see k8worker in ready status on the master-node. At this point, you have now successfully deployed a Kubernetes cluster on CentOS 8.