Multi-Node Kubernetes Cluster

Multi-Node Kubernetes Cluster

This is my first article on Kubernetes, so let's start with What is Kubernetes? Kubernetes are also known as k8s. It is an open-source container orchestration system for automating computer application deployment, scaling, and management. It was originally designed by Google and is now maintained by the Cloud Native Computing Foundation.

Now The question that arises in my mind is what is Multi-Node Cluster? Well... Multi-cluster is a strategy for deploying an application on or across multiple Kubernetes clusters with the goal of improving availability, isolation, and scalability. Multi-cluster can be important to ensure compliance with different and conflicting regulations, as individual clusters can be adapted to comply with geographic- or certification-specific regulations.

So, you must be wondering why only Multi-node Cluster so the answer to your this question is:- 1- Improved Operational Readiness. 2- Isolation and Multi-Tenancy 3- Increased Availability and Performance 4- Compliance 5- Eliminate Vendor Lock-In

Here in this article, we are going to create our own multi-node Kubernetes cluster on redhat8 using kubeadm. Although Minikube is the easiest and fastest way to set up a single-node cluster but for Multi-Node cluster, kubeadm is the easiest way to set up a cluster.

Requirements for each node (Master Node as well as slave node):-

Operating System (I m using RHEL 8), installing docker, configuring yum, kubelet, setup Kubernetes environment, disabling swap, firewall, SELinux, make them pingable to each other. These programs are required in master node as well as slave node, so to save our time we will set up all the programs in one OS and then clone the others with similar settings.

Here I am using Oracle Virtual box and on top of it, I will run RHEL8 Linux OS. One master node and two slave node to create an entire multinode cluster. we will start by installing redhat8 on top of Virtualbox.

* Create a new Virtual Machine.

No alt text provided for this image
No alt text provided for this image









Click Next and Provide at least 2 GB Ram.

No alt text provided for this image







Click Next and give the hard disk at least 8gb and then click create. Go to Settings->system and give the hard disk the top priority, in Processor give at least 2 CPU, go to storage and attach the iso file and from the network select the bridge adapter (for the connectivity from outside the cluster as well as between the nodes in the cluster). as shown in the pictures below:

No alt text provided for this image
No alt text provided for this image

Now Click Start. Select Minimal installation and disable KDUMP. for networking turn, the ethernet on, leave the installation destination as it is just click done. set the root password and confirm it, as shown in the pictures below.

No alt text provided for this image
No alt text provided for this image


No alt text provided for this image
No alt text provided for this image

Click on begin the installation and wait as it will take some time for installation.

* Configure Yum.

Make a folder to mount the dvd of rhel8. Now configure yum using the command

vi /etc/yum.repos.d/dvd.repo

No alt text provided for this image

This is in dvd.repo file (press I to insert and press Esc and do :wq to save and exit from the file)

No alt text provided for this image

To see the status of the software run the below command.

No alt text provided for this image

After configuring yum, now we can install ifconfig command from the net-tools software to see IP and install vim (to open file).

In my case, the software is already installed.

No alt text provided for this image

Now, we can see the IP using ifconfig command.

No alt text provided for this image

Now login from PUTTY tool because CLI is difficult to copy and paste.

No alt text provided for this image

We can change the font according to our ease.

No alt text provided for this image

* Install docker on RHEL8.

To do this we have to configure docker repo and then install docker.

No alt text provided for this image
No alt text provided for this image

Now, install docker with the command yum install docker-ce --nobest (put two hyphen before nobest).

In My case, it is already installed.

No alt text provided for this image

*Disable firewall

No alt text provided for this image

*Make the dvd mount permanent so that after reboot no need to mount again and again.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

These above commands will mount the dvd permanently.

* Now we have to set up Kubernetes Environment by configuring Kubernetes repo. This program you can get on google by searching Kubernetes repo

No alt text provided for this image

To check go to cd /etc/yum.repos.d/ folder

No alt text provided for this image

* Run the below command to install kubelet software.

No alt text provided for this image
No alt text provided for this image

This will install the software .

* We have to disable SELinux to make this software work properly.

No alt text provided for this image

open this file vim /etc/selinux/config and make selinux disable or permissive.

No alt text provided for this image

* Now start the docker services.

No alt text provided for this image

If docker info command gives output that means everything is working fine. Now from docker info command, change the Cgroup Driver from cgroupfs to "systemd" . you can find this file by searching on google

No alt text provided for this image
No alt text provided for this image

open the above file and press I to insert and for saving and exiting (press Esc button and :wq)

No alt text provided for this image

** Remember whenever you make any changes you did to restart the services.

No alt text provided for this image

* Disable Swap

open the vim /etc/fstab file and make the swap line comment or just delete it.

No alt text provided for this image

* Now for controlling the traffic on Linux install "iproute-tc" software using yum.

In my case, it is already installed.

No alt text provided for this image

As from the above command, the status of iptables is 1 and it should be 1 only. Incase it doesn't show 1 then from google run the below-selected command.

No alt text provided for this image

* Now Start the Kubelet services and enable them.

No alt text provided for this image

These all are the necessary steps that you did to do before setting up the cluster.

* Now its time to clone our master and slave nodes from the above created OS. For my cluster, I am taking one master and two slaves but it can vary according to one's requirement.

No alt text provided for this image
No alt text provided for this image

Similarly, clone the other two slave node also.

* Set the hostname so that nodes can ping each other with hostname as IP are not reliable. exec bash command (it set the hostname without logging out of the system).

No alt text provided for this image

open vim /etc/hosts file and set IP and hostname of each node.

No alt text provided for this image

To Copy vim /etc/hosts file to other nodes We have command:- scp /etc/hosts (with IP of the other node where you are copying and the destination where you want to copy)

No alt text provided for this image

** Make Sure all the nodes are pingable to each other with their names.

No alt text provided for this image

*Now we are going to initialize the kubeadm program with IP and netmask on our master node.

No alt text provided for this image

If it shows Running pre-flight checks (that means you haven't missed any step and everything is working fine).

No alt text provided for this image
No alt text provided for this image

copy these selected lines and paste on the master node.

No alt text provided for this image

Now copy the above token command to run on the slave nodes but before that we need to set the overlay network between the slave nodes using Flannel plugins. so for now copy this token command on the notepad

So for Flannel go to google

No alt text provided for this image
No alt text provided for this image

The above command will download the flannel plugins.

Now, run kubectl get nodes command, you will see our master node is ready.

No alt text provided for this image

Now, at all the slave nodes run the token command which you have saved earlier on the notepad (so that all the worker nodes can join to the master node).

No alt text provided for this image

In the master run the following commands:-

No alt text provided for this image

So all the nodes are ready and all steps are done successfully and the Our Cluster is Ready.

* * It is important to make IP permanent because after reboot IP might change and we can loose our clients. To make it permanent run below commands:-

[root@master ~]# nmcli con add type ethernet con-name lwstatic ifname enp0s3 ip4 192.168.1.11/24 gw4 192.168.0.1

[root@master ~]# nmcli con mod lwstatic ipv4.dns 192.168.0.1

[root@master ~]# nmcli con down enp0s3 ; nmcli con up lwstatic

[root@master ~]# nmcli connection show

Now copy config file from the master node to the windows using WinSCP tool.

No alt text provided for this image
No alt text provided for this image

So config file is successfully copied. In my case I am using windows as my client source and there I have minikube and kubectl services installed on top of Virtualbox , now I will connect to my multi-node cluster using the config file on windows command prompt.

Our multinode cluster is ready to use and in that command, we have to use --kubeconfig config for connecting to our cluster.

No alt text provided for this image

Now I am launching a pod using replicaset with replica-2. You will see that the pods will be created in different slaves and within the mentioned IP range.

No alt text provided for this image

This is the yml code to create a ReplicaSet.

No alt text provided for this image
No alt text provided for this image

As you can see in the above image repilcaset has created two pods and both in different slaves.

Now we will expose our rs using type Nodeport(for the outside connectivity) and port no 80 (as most of the apache web server run on port no 80). It will randomly provide you with the port number.

No alt text provided for this image

Now, go to google and type the IP of any one of your slaves with the port number provided.

No alt text provided for this image

This is My Final Output.

Thank you so much Vimal Daga Sir for providing knowledge on this topic which assisted me in doing and completing this task. #righteducation #vimaldaga #linuxworld #worldrecordholder #redhat #Kubernetes #multi-nodecluster #k8s.




























Shalini Gairola

Student at DAV Post Graduate College

4y

Great work....👍

Good job...keep it going !

To view or add a comment, sign in

More articles by Mansi Bhandari

Insights from the community

Others also viewed

Explore topics