Install And Configure Kubernetes On Master Node And Each Worker Node.

First of all, we need to add the Kubernetes package to the CentOs directory, because it is also absent in the default CentOS package. For this, we create a new file (use Vim or Nano text editor) and add the following content to the file.

In this example, we will use a nano text editor. First of all install nano editor if it is not already installed and then create the file.

sudo yum install nano -y
sudo nano /etc/yum.repos.d/kubernetes.repo
Paste following content to the file.
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg

Explanation About the Above Code

  1. Baseurl: URL from where the package manager pulls the Kubernetes packages.
  2. enabled: Indicate that repository is enabled and can be used for package installations and updates.
  3. gpgcheck: Indicate that the package manager will verify the GPG signatures of the packages.
  4. repo_gpgcheck: Ensures that the repository is trusted and gpgkey should be checked.
  5. gpgkey: URLs where the GPG keys located
    Once pasted, press Ctrl+O, then Enter to save it. Then press Ctrl+X to exit.

After adding the Kubernetes package to the CentOs directory we can now install kubernetes services. For that, we need to execute the following command.

sudo yum install -y kubelet kubectl kubeadm

Where kubelet is needed for running and managing containers in s Kubernetes cluster. Kubectl needed to cooperate with a Kubernetes cluster. Kubeadm is needed for bootstrapping the new cluster. After the execution command, you will see that all three services are successfully installed.

In the next step, we will change our VMs’ names. This is necessary for a convenient understanding of our hostname. On Master Node we need to execute the following command:

sudo hostnamectl set-hostname master-node

On Worker Node-1 we need to execute the following command:

sudo hostnamectl set-hostname worker-node-1

On Worker Node-2 we need to execute the following command:

sudo hostnamectl set-hostname worker-node-2

Change your “hosts” file and add IP address and your new hostname from previous commands to the end of the file.

sudo nano /etc/host

In order to be sure that nothing will interfere with the Kubernetes work, we need to disable the swap. Because kubernetes will manage memory when running containers.

sudo sed -i '/swap/d' /etc/fstab
sudo swapoff -a

Also, we need to disable SELinux to avoid any potential conflicts or issues that may arise during the installation process. For that execute the following commands.

sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

After the previous command, we also need to enable br_netfilter kernel module so that the packets, that passing through the bridge, will beprocessed by iptables for filtering and for port forwarding, and the kubernetes pods across the cluster could communicate with each other.

echo '1' > /proc/sys/net/ipv4/ipforward

Fire Wall Rules on Master Node

For persistent communication between virtual machines, pods, and containers, we need to add new firewall rules.

sudo firewall-cmd --permanent --add-port=6443/tcp
sudo firewall-cmd --permanent --add-port=2379-2380/tcp
sudo firewall-cmd --permanent --add-port=10250/tcp
sudo firewall-cmd --permanent --add-port=10251/tcp
sudo firewall-cmd --permanent --add-port=10252/tcp
sudo firewall-cmd --permanent --add-port=10255/tcp
sudo firewall-cmd --reload

Fire Wall On Worker Node

As well as we need to add firewall to worker nodes also.

sudo firewall-cmd --permanent --add-port=10251/tcp
sudo firewall-cmd --permanent --add-port=10255/tcp
sudo firewall-cmd --reload

How To Deploy Kubernetes on CentOS?

Kubernetes cluster is a set of nodes that execute applications within containers. Clusters consist of a master node and several worker nodes. These nodes could be physical computers or virtual machines. It depends on the configuration of the cluster. The master node manages and coordinates the worker node. The worker nodes are responsible for executing tasks and running containerized applications by the master node’s directions.

steps needed to deploy Kubernetes on CentOS. We will install container runtime, install Kubernetes on CentOS, create Kubernetes Cluster, and connect Worker nodes to the cluster.

Similar Reads

Install Container Run Time On Master Node And Each Worker Node

First of all, for installing Kubernetes, we need to have one of the container runtime services. In this tutorial, we will use Containerd. Containerd is a container runtime that manages the lifecycle of a container virtual machine. It is a process, which creates, starts, stops, and destroys containers. It is also can download container images from container registries, mount storage, and enable networking for a container....

Install And Configure Kubernetes On Master Node And Each Worker Node.

First of all, we need to add the Kubernetes package to the CentOs directory, because it is also absent in the default CentOS package. For this, we create a new file (use Vim or Nano text editor) and add the following content to the file....

Deploy Kubernetes Cluster

The first thing we have to do is initialize a cluster.On Master Node execute the following command....

Join Worker Node to the Cluster

For this, we need to generate a join command. To get it, execute the following command on Master Node....

Contact Us