Home / Linux / How to Install a Kubernetes Cluster on CentOS 8

How to Install a Kubernetes Cluster on CentOS 8

How to Install a Kubernetes Cluster on CentOS 8

The course of of putting in a Kubernetes Cluster on CentOS 8 is nearly comparable to that of CentOS 7 (which you’ll be able to undergo right here), however the course of right here has a few modifications. These modifications, largely revolve across the set up of Docker.

Starting from CentOS 8 (and by extension RHEL 8), docker has now natively been changed by podman and buildah that are instruments from Redhat. As a matter of truth, the docker package deal has now been faraway from the default package deal repository.

With this transfer, the Redhat crew goals to simplify the method of making and utilizing containers, while not having particular permissions, whereas on the similar time, sustaining compatibility with docker pictures and working them while not having a daemon. Podman guarantees to provide extra flexibility when working on Kubernetes environments, however the jury stays on the market.

For this text, we are going to run by the method of putting in Kubernetes on a CentOS 8 platform, working on Docker-CE (Community Edition). In a later article, we may also run by a comparable set up, utilizing podman for our containers.

Prerequisites

  1. Three servers working CentOS 81 Master Node and 2 Worker Nodes.
  2. It is really useful that your nodes ought to have not less than 2 CPUs with 2GB RAM or extra per machine. This shouldn’t be a strict requirement however is basically pushed by the wants of the applying you plan to run.
  3. Internet connectivity on all of your nodes. We will likely be fetching Kubernetes and docker packages from the repository. Equally, you will have to be sure that the DNF package deal supervisor is put in by default and might fetch packages remotely.
  4. All your nodes must also have the ability to join to each other, both on a personal or public community, whichever is offered.
  5. You may also want entry to an account with sudo or root privileges. In this tutorial, I will likely be utilizing my root account.

Precaution

Most nodes usually include distinctive MAC addresses, nonetheless, in some distinctive instances, some Virtual Machines might have an identical MAC addresses. It is subsequently really useful that you just affirm that the Product_UUID and the MAC deal with aren’t an identical in any of the nodes.

Kubernetes makes use of these values to uniquely determine the nodes within the cluster. If these values aren’t distinctive to every node, the set up course of might fail.

To examine the MAC deal with of the community interface and evaluate it.

# ip hyperlink

To examine the product_uuid and evaluate, run the next command.

# cat /sys/class/dmi/id/product_uuid 

Logical Architecture

Our set up is designed to have the Master-Node controlling the Worker Nodes. At the tip of this set up, our logical structure will look one thing like this.

Master Node – This machine usually acts because the management airplane and runs the cluster database and the API server (which the kubectl CLI communicates with).

Our Three-node Kubernetes Cluster will look one thing like this:

Kubernetes Cluster DiagramKubernetes Cluster Diagram

Kubernetes Cluster Diagram

Installation of Kubernetes Cluster on Master-Node

For Kubernetes to work, you will have a containerization engine. As talked about, we will likely be utilizing Docker-CE.

The following establishments will likely be carried out on CentOS 8 Master-Node.

Step 1: Prepare Hostname, Firewall, and SELinux

On your CentOS 8 Master-Node, set the system hostname and replace DNS in your /and so on/hosts file.

# hostnamectl set-hostname master-node
# cat <<EOF>> /and so on/hosts
192.168.zero.47 master-node
192.168.zero.48 node-1 worker-node-1
192.168.zero.49 node-2 worker-node-2
EOF

Next, ping your worker-node-1 and worker-node-2 to examine in case your up to date host file is working accurately utilizing the ping command.

# ping 192.168.zero.48
# ping 192.168.zero.49

Next, disable Selinux, as that is required to permit containers to entry the host filesystem, which is required by pod networks and different providers.

# setenforce zero

Setting setenforce to zero successfully units SELinux to permissive, which successfully disables SELinux till the subsequent reboot. To fully disable it, use the beneath command and reboot.

# sed -i --follow-symlinks 's/SELINUX=implementing/SELINUX=disabled/g' /and so on/sysconfig/selinux
# reboot

Kubernetes makes use of varied ports for communication and entry and these ports want to be accessible to Kubernetes and never restricted by the firewall.

Kubernetes PortsKubernetes Ports

Kubernetes Ports

Configure the firewall guidelines on the ports.

# firewall-cmd --permanent --add-port=6443/tcp
# firewall-cmd --permanent --add-port=2379-2380/tcp
# firewall-cmd --permanent --add-port=10250/tcp
# firewall-cmd --permanent --add-port=10251/tcp
# firewall-cmd --permanent --add-port=10252/tcp
# firewall-cmd --permanent --add-port=10255/tcp
# firewall-cmd –reload
# modprobe br_netfilter
# echo '1' > /proc/sys/internet/bridge/bridge-nf-call-iptables

Step 2: Install Docker-CE on CentOS 8

You will want to add the Docker repository first as it’s now not within the default package deal record utilizing the next dnf config-manager command.

# dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo

Also set up containerd.io package deal which is offered as a daemon that manages the whole container lifecycle of its host system, from picture switch and storage to container execution and supervision to low-level storage to community attachments and past.

# dnf set up https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm

Now set up the newest model of a docker-ce package deal.

# dnf set up docker-ce

You can now allow and begin the docker service.

# systemctl allow docker
# systemctl begin docker

Step Three: Install Kubernetes (Kubeadm) on CentOS 8

Next, you will have to add Kubernetes repositories manually as they don’t come put in by default on CentOS 8.

# cat <<EOF > /and so on/yum.repos.d/kubernetes.repo
[kubernetes]
identify=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
EOF

Kubeadm helps you bootstrap a minimal viable Kubernetes cluster that conforms to finest practices. With kubeadm, your cluster ought to move the Kubernetes Conformance exams.

Kubeadm additionally helps different cluster lifecycle capabilities, corresponding to upgrades, downgrade, and managing bootstrap tokens. Kubeadm can be integration-friendly with different orchestration instruments like Ansible and Terraform.

With the package deal repo now prepared, you may go forward and set up kubeadm package deal.

# dnf set up kubeadm -y 

When the set up completes efficiently, allow and begin the service.

# systemctl allow kubelet
# systemctl begin kubelet

Step four: Create a control-plane Master with kubeadm

The Kubernetes grasp which acts because the management airplane for the cluster runs a few important providers vital for the cluster. As such, the initialization course of will do a collection of prechecks to be certain that the machine is prepared to run Kubernetes. These prechecks expose warnings and exit on errors. kubeadm init then downloads and installs the cluster management airplane parts.

Now it’s time to initialize Kubernetes grasp, however earlier than that, you have to disable swap so as to run “kubeadm init“ command.

# swapoff -a

Initializing Kubernetes grasp is a fully automated course of that’s managed by the “kubeadm init“ command as proven.

# kubeadm init
Initialize Kubernetes MasterInitialize Kubernetes Master

Initialize Kubernetes Master

Next, copy the next command and retailer it someplace, as we required to run this command on the employee nodes later.

kubeadm be a part of 192.168.zero.47:6443 --token nu06lu.xrsux0ss0ixtnms5   --discovery-token-ca-cert-hash ha256:f996ea35r4353d342fdea2997a1cf8caeddafd6d4360d606dbc82314683478hjmf7

Tip: Sometimes the above command may throw errors concerning the arguments handed, so to keep away from errors, you want to take away the ‘’ character and your closing command will seem like this.

# kubeadm be a part of 192.168.zero.47:6443 --token nu06lu.xrsux0ss0ixtnms5 –discovery token-ca-cert-hash sha256:f996ea35r4353d342fdea2997a1cf8caeddafd6d4360d606dbc82314683478hjmf7

Once Kubernetes initialized efficiently, you have to allow your person to begin utilizing the cluster. In our situation, we will likely be utilizing the basis person. You may begin the cluster utilizing sudo person as proven.

To use root, run:

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

To use a sudo enabled person, run:

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

Now affirm that the kubectl command is activated.

# kubectl get nodes
Check Status of NodesCheck Status of Nodes

Check Status of Nodes

At this second, you will note the standing of the master-node is ‘NotReady’. This is as a result of we’re but to deploy the pod community to the cluster.

The pod Network is the overlay community for the cluster, that’s deployed on prime of the current node community. It is designed to permit connectivity throughout the pod.

Step 5: Setup Your Pod Network

Deploying the community cluster is a extremely versatile course of relying on your wants and there are numerous choices obtainable. Since we wish to preserve our set up so simple as doable, we are going to use Weavenet plugin which doesn’t require any configuration or further code and it offers one IP deal with per pod which is nice for us. If you need to see extra choices, please examine right here.

These instructions will likely be necessary to get the pod community setup.

# export kubever=$(kubectl model | base64 | tr -d 'n')
# kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$kubever
Setup Pod NetworkSetup Pod Network

Setup Pod Network

Now should you examine the standing of your master-node, it must be ‘Ready’.

# kubectl get nodes
Check Status of Master NodesCheck Status of Master Nodes

Check Status of Master Nodes

Next, we add the employee nodes to the cluster.

Adding Worker Nodes to Kubernetes Cluster

The following directions will likely be carried out on every employee node when becoming a member of the Kubernetes cluster.

Step 1: Prepare Hostname, Firewall, and SELinux

First set the hostname on your worker-node-1 and worker-node-2, after which add the host entries to the /and so on/hosts file.

# hostnamectl set-hostname 'node-1'
# cat <<EOF>> /and so on/hosts
192.168.zero.47 master-node
192.168.zero.48 node-1 worker-node-1
192.168.zero.49 node-2 worker-node-2
EOF

Next, ping your grasp node out of your employee nodes to affirm that your up to date host file is working tremendous utilizing the ping command.

# 192.168.zero.47

Next, disable SElinux and replace your firewall guidelines.

# setenforce zero
# sed -i --follow-symlinks 's/SELINUX=implementing/SELINUX=disabled/g' /and so on/sysconfig/selinux
# firewall-cmd --permanent --add-port=6783/tcp
# firewall-cmd --permanent --add-port=10250/tcp
# firewall-cmd --permanent --add-port=10255/tcp
# firewall-cmd --permanent --add-port=30000-32767/tcp
# firewall-cmd  --reload
# echo '1' > /proc/sys/internet/bridge/bridge-nf-call-iptables

Step 2: Setup Docker-CE and Kubernetes Repo

Add the Docker repository first utilizing DNF config-manager.

# dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo

Next, add the containerd.io package deal.

# dnf set up https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm

With these two packages put in, set up the newest model of docker-ce.

# dnf set up docker-ce

Enable and begin the docker service.

# systemctl allow docker
# systemctl begin docker

You will want to add Kubernetes repositories manually as they don’t come pre-installed on CentOS 8.

# cat <<EOF > /and so on/yum.repos.d/kubernetes.repo
[kubernetes]
identify=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
EOF

Step Three: Install Kubeadm on CentOS 8

With the package deal repo now prepared, you may go forward and set up kubeadm.

# dnf set up kubeadm -y 

Start and allow the service.

# systemctl allow kubelet
# systemctl begin kubelet

Step four: Join the Worker Node to the Kubernetes Cluster

We now require the token that kubeadm init generated, to be a part of the cluster. You can copy and paste it to your node-1 and node-2 should you had copied it someplace.

# kubeadm be a part of 192.168.zero.47:6443 --token nu06lu.xrsux0ss0ixtnms5  --discovery-token-ca-cert-hash sha256:f996ea35r4353d342fdea2997a1cf8caeddafd6d4360d606dbc82314683478hjmf78

As steered on the final line, return to your master-node and confirm if employee node-1 and employee node-2 have joined the cluster utilizing the next command.

# kubectl get nodes
Check All Nodes Status in Kubernetes ClusterCheck All Nodes Status in Kubernetes Cluster

Check All Nodes Status in Kubernetes Cluster

If all of the steps run efficiently, then, it is best to see node-1 and node-2 in prepared standing on the master-node. At this level, you may have now efficiently deployed a Kubernetes cluster on CentOS 8.

Some Limitations

The cluster we now have created right here has a single Master node, and as such, if the Master node fails, your cluster might lose knowledge and might have to be recreated from scratch.

For this purpose, I like to recommend a Highly Available setup.

About Agent

Check Also

Do x86_64bit ISO Works On 32bit Only And 64bit Only CPU ? : linux

Do x86_64bit ISO Works On 32bit Only And 64bit Only CPU ? : linux

Do x86_64bit ISO Works On 32bit Only And 64bit Only CPU ? : linux What …

Leave a Reply

Your email address will not be published. Required fields are marked *