{{announcement.body}}
{{announcement.title}}

Kubernetes Installation in RedHat/CentOS

DZone 's Guide to

Kubernetes Installation in RedHat/CentOS

In this article, take a look at a tutorial on Kubernetes installation in RedHat/CentOS.

· Cloud Zone ·
Free Resource

Welcome! In this article, we are going to look at how to configure Kubernetes cluster for container orchestration.

Before reading this article, you should know basic core concepts of kubernetes components and basic administration in Redhat OS or CentOS

Prerequisites:

  • Hosts - 2 or 3 Machines (node) requiredRAM - 4 GB
  • Storage - 50 GB
  • CPU - 2 CPU

Let’s start how to install and configure Kubernetes in Redhat Enterprise Linux.

Here we are going to configure Kubernetes cluster using 4 VM’s.

  • One VM – Master Node
  • Other three VM’s – Worker Nodes

Steps for Kubernetes Cluster Configuration

Step1: Set Hostname with its IP address

Add the Hostname of all Hosts with those IP address (Consider all Hosts or VM as Nodes)

Run the below command to go Hosts file location to change host name with its IP

Java
 






 

“Hostname with its IP (We need separate IP for each host or node)” 

We just gave the below names

  • Master node name – k8master
  • Worker nodes name – knode1, knode2, knode3

Step 2: Update OS

Keep the OS Up to date

Run the below Command to update OS

Java
 







Step 3: Disable SElinux 

By disabling the SElinux, all containers can easily access the host filesystem.

We can Disable SElinux by two methods

  1. Run the below command
Java
 






 

  1. Go to SELinux configuration file and disable it

Run the below command

Java
 







Step 4: Disable or Off the SWAP

By disabling the SWAP, kubelet will work perfectly.

Run the below command to disable SWAP:

Java
 







Step 5: To Allow Ports in Firewall or Disable Firewall

By allowing the below ports or disabling firewall, all containers, network drivers, and pods are communicating across the kubernetes cluster properly

Run the following command to allow ports in firewall:

Java
 







Run the below command to disable firewall (This step is not recommended for production environment, but in this article, we are going to do disable firewall)

Java
 






 

Step 6: To update the IP Tables run the following command

By updating IP Tables, Port forwarding and Filtering process will work perfectly

Run the below command to update the IP tables:

Java
 







Step 7: To Install Docker and Kubernetes in nodes, need to configure docker and Kubernetes repositories

 

Kubernetes: - Run the below command to add Kubernetes repo

Java
 







Paste the below details in nano editor

Java
 







You can see below screenshot I have added the above details in all four VM’s and save the file

Docker:- Run the below command to add docker repo

Java
 






 

To download external packages:- Run the below command to get all docker and Kubernetes packages from docker and google repos without any issues

Java
 







Up to this, you can see all the steps in below snap.

Step 8: To install the docker and Kubernetes components

Run the following command to install the Kubenetes/Docker (kublet kubeadm kubectl docker)

Java
 




xxxxxxxxxx
1


 
1
yum install kubelet kubeadm kubectl docker -y



Step 9: To start and enable Kubernetes and docker services

Run the below commands to start:

Java
 







Java
 







Step 10: To run cluster configuration in Master node, this step should follow only in master node

Run the below command to start cluster configuration in master node

Java
 






 

apiserver address must be masternode IP (10.1.5.46) address

You can see the below output

After the successful start of kubadm master, we need to run the above-shown command from the non-root or root user then only a user can control the kubectl commands.

Run the command

Java
 







Run the command

Java
 







Step 11: To check the all pods are running successful in cluster 

Run the command you can see all pods in namespaces

Java
 







You can see the coredns service not yet started, still in pending, So that we need to install flannel network plugin to run coredns to start pod network communication.

Step 12: To Install Flannel Pod network driver

Run the below command to install POD network

Java
 






 

Now you can see coredns and all pods in namespaces are in ready and running successfully.

Step 13: To Taint master node as a Master 

Run the below command to taint the master node and make as a master.

Java
 






 

Step 14: Join the Worker Nodes to Master Node.

Run the token which produced by master node in other nodes to join to the cluster. 

Generated Token:-

Java
 







Run the command to check all the nodes are connected to cluster or not

Java
 







Step 15: To Install and configure Kubernetes Dashboard

Run the Below Command to install the dashboards

Java
 







Create a service account dashboard(username) for dashboard to access it

Java
 







Run the Below command to give admin access to user(dashboard) to bind with cluster for accessing dashboard.

Java
 







Run the below command to generate the secret key for user(dashboard), to access Kubernetes dashboard

Java
 







You can see the generated key below, copy and save it.

To start the dashboard service, Run the below command.

Java
 







Paste and Go to the below URL in Master Node and click the token radio button and then paste the generated access token.

http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/.

After signing in you can see the Kubernetes dashboard

In the end, we completed our Kubernetes cluster configuration setup successfully.

I hope you love this article; please share and like it.

Cheers,

Gokulakrishna

Topics:
centos ,kubernetes ,kubernetes cluster ,redhat ,tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}