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.
Click Next and Provide at least 2 GB Ram.
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:
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.
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
This is in dvd.repo file (press I to insert and press Esc and do :wq to save and exit from the file)
To see the status of the software run the below command.
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.
Now, we can see the IP using ifconfig command.
Now login from PUTTY tool because CLI is difficult to copy and paste.
We can change the font according to our ease.
* Install docker on RHEL8.
To do this we have to configure docker repo and then install docker.
Now, install docker with the command yum install docker-ce --nobest (put two hyphen before nobest).
In My case, it is already installed.
*Disable firewall
*Make the dvd mount permanent so that after reboot no need to mount again and again.
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
To check go to cd /etc/yum.repos.d/ folder
* Run the below command to install kubelet software.
This will install the software .
* We have to disable SELinux to make this software work properly.
open this file vim /etc/selinux/config and make selinux disable or permissive.
* Now start the docker services.
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
open the above file and press I to insert and for saving and exiting (press Esc button and :wq)
** Remember whenever you make any changes you did to restart the services.
* Disable Swap
open the vim /etc/fstab file and make the swap line comment or just delete it.
* Now for controlling the traffic on Linux install "iproute-tc" software using yum.
In my case, it is already installed.
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.
* Now Start the Kubelet services and enable them.
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.
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).
open vim /etc/hosts file and set IP and hostname of each node.
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)
** Make Sure all the nodes are pingable to each other with their names.
*Now we are going to initialize the kubeadm program with IP and netmask on our master node.
If it shows Running pre-flight checks (that means you haven't missed any step and everything is working fine).
copy these selected lines and paste on the master node.
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
The above command will download the flannel plugins.
Now, run kubectl get nodes command, you will see our master node is ready.
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).
In the master run the following commands:-
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.
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.
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.
This is the yml code to create a ReplicaSet.
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.
Now, go to google and type the IP of any one of your slaves with the port number provided.
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.
Student at DAV Post Graduate College
4yGreat work....👍
Trainee
4yGood job...keep it going !