DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Spinnaker Meets Minikube: Part 1
  • Create a Kubernetes Cluster With Centos
  • Establishing a Highly Available Kubernetes Cluster on AWS With Kops
  • Kubernetes Remote Development in Java Using Kubernetes Maven Plugin

Trending

  • Accelerating AI Inference With TensorRT
  • AI's Dilemma: When to Retrain and When to Unlearn?
  • Rust and WebAssembly: Unlocking High-Performance Web Apps
  • Debugging Core Dump Files on Linux - A Detailed Guide
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Kubernetes Installation in RedHat/CentOS

Kubernetes Installation in RedHat/CentOS

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

By 
Gokulakrishna G user avatar
Gokulakrishna G
·
May. 22, 20 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
12.9K Views

Join the DZone community and get the full member experience.

Join For Free

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
 




xxxxxxxxxx
1


 
1
nano /etc/hosts


 

“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
 




xxxxxxxxxx
1


 
1
yum update -y



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
 




xxxxxxxxxx
1


 
1
setenforce 0
2

          
3
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config


 

  1. Go to SELinux configuration file and disable it

Run the below command

Java
 




xxxxxxxxxx
1


 
1
nano /etc/sysconfig/selinux and type SELINUX=disabled
2

          



Step 4: Disable or Off the SWAP

By disabling the SWAP, kubelet will work perfectly.

Run the below command to disable SWAP:

Java
 




xxxxxxxxxx
1


 
1
swapoff -a && sed -i '/swap/d' /etc/fstab



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
 




xxxxxxxxxx
1
13


 
1
firewall-cmd --permanent --add-port=6443/tcp
2

          
3
firewall-cmd --permanent --add-port=2379-2380/tcp
4

          
5
firewall-cmd --permanent --add-port=10250/tcp
6

          
7
firewall-cmd --permanent --add-port=10251/tcp
8

          
9
firewall-cmd --permanent --add-port=10252/tcp
10

          
11
firewall-cmd --permanent --add-port=10255/tcp
12

          
13
firewall-cmd –-reload



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
 




xxxxxxxxxx
1


 
1
systemctl stop firewalld
2

          
3
systemctl disable firewalld


 

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
 




xxxxxxxxxx
1


 
1
modprobe br_netfilter
2

          
3
echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables



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
 




xxxxxxxxxx
1


 
1
nano /etc/yum.repos.d/kubernetes.repo



Paste the below details in nano editor

Java
 




xxxxxxxxxx
1
15


 
1
[kubernetes]
2

          
3
name=Kubernetes
4

          
5
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
6

          
7
enabled=1
8

          
9
gpgcheck=1
10

          
11
repo_gpgcheck=1
12

          
13
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
14

          
15
        https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg



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
 




xxxxxxxxxx
1


 
1
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo


 

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

Java
 




xxxxxxxxxx
1


 
1
subscription-manager repos --enable=rhel-7-server-extras-rpms



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
 




xxxxxxxxxx
1


 
1
systemctl start docker && systemctl enable docker



Java
 




xxxxxxxxxx
1


 
1
systemctl start kubelet && systemctl enable kubelet



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
 




xxxxxxxxxx
1


 
1
kubeadm init --apiserver-advertise-address=10.1.5.46 --ignore-preflight-errors all --pod-network-cidr=10.244.0.0/16 --token-ttl 0


 

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
 




xxxxxxxxxx
1


 
1
mkdir -p $HOME/.kube
2

          
3
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config



Run the command

Java
 




xxxxxxxxxx
1


 
1
sudo chown $(id -u):$(id -g) $HOME/.kube/config



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

Run the command you can see all pods in namespaces

Java
 




xxxxxxxxxx
1


 
1
kubectl get pods –all-namespaces



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
 




xxxxxxxxxx
1


 
1
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml


 

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
 




xxxxxxxxxx
1


 
1
kubectl taint nodes --all node-role.kubernetes.io/master-


 

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
 




xxxxxxxxxx
1


 
1
kubeadm join 10.1.5.46:6443 –token lixbn2.aea4n63ypd42578



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

Java
 




xxxxxxxxxx
1


 
1
Kubectl get nodes



Step 15: To Install and configure Kubernetes Dashboard

Run the Below Command to install the dashboards

Java
 




xxxxxxxxxx
1


 
1
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta8/aio/deploy/recommended.yaml



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

Java
 




xxxxxxxxxx
1


 
1
kubectl create serviceaccount dashboard -n default



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

Java
 




xxxxxxxxxx
1


 
1
kubectl create clusterrolebinding dashboard-admin -n default  --clusterrole=cluster-admin --
2

          
3
serviceaccount=default:dashboard



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

Java
 




xxxxxxxxxx
1


 
1
kubectl get secret $(kubectl get serviceaccount dashboard -o jsonpath="{.secrets[0].name}") -o jsonpath="{.data.token}" | base64 --decode



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

To start the dashboard service, Run the below command.

Java
 




xxxxxxxxxx
1


 
1
kubectl proxy



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

Kubernetes Docker (software) Java (programming language) Command (computing) master Host (Unix)

Opinions expressed by DZone contributors are their own.

Related

  • Spinnaker Meets Minikube: Part 1
  • Create a Kubernetes Cluster With Centos
  • Establishing a Highly Available Kubernetes Cluster on AWS With Kops
  • Kubernetes Remote Development in Java Using Kubernetes Maven Plugin

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!