Kubernetes Installation In Redhat And CentOS

Before reading this article, you should know the basic core concepts of Kubernetes components and basic administration in Redhat OS or CentOS.
 
Prerequisites
  • Hosts - 2 or 3 Machines (node) required.
  • RAM - 4 GB
  • Storage - 50 GB
  • CPU - 2 CPU
Let’s start and see 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

 
Step 1 - Set Hostname with its IP address
 
Add the Hostname of all Hosts with those IP addresses (Consider all Hosts or VM as Nodes).
 
Run the below command to go to host file location to change host name with its IP.
 
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
 
Kubernetes Installation In Redhat And CentOS 
 
Step 2 - Update OS
 
Keep the OS up to date
 
Run the below command to update the OS:
 
yum update -y
 
Kubernetes Installation In Redhat And CentOS 
 
Step 3 - Disable SElinux
 
By Disabling the SElinux all containers can easily access host filesystem.
 
We can disable SElinux by two methods.
 
Run the below command:
 
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
 
Kubernetes Installation In Redhat And CentOS 
 
Go to SELinux configuration file and disable it
 
Run the below command:
 
nano /etc/sysconfig/selinux and type SELINUX=disabled
 
Kubernetes Installation In Redhat And CentOS 
 
Step 4 - Disable or Off the SWAP
 
By disabling the SWAP kubelet will work perfectly.
 
Run the below command to disable SWAP:
 
swapoff -a && sed -i '/swap/d' /etc/fstab
 
Kubernetes Installation In Redhat And CentOS 
 
Step 5 - To allow ports in firewall or to 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:
 
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
 
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.)
 
systemctl stop firewalld
systemctl disable firewalld
 
Kubernetes Installation In Redhat And CentOS
 
Kubernetes Installation In Redhat And CentOS 
 
Step 6 - To update the IP Tables run the following command
 
By updating IP Tables, the port forwarding and filtering process will work perfectly.
 
Run the below command to update the IP tables:
 
modprobe br_netfilter
echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables
 
Kubernetes Installation In Redhat And CentOS
 
Step 7 - To Install Docker and Kubernetes in nodes, we need to configure Docker and Kubernetes repositories.
 
Kubernetes: - Run the below command to add Kubernetes repo.
 
nano /etc/yum.repos.d/kubernetes.repo
 
Paste the below details in nano editor:
 
[kubernetes]
name=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
 
You can see int he below screenshot I have added the above details in all four VM’s and saved the file.
 
Kubernetes Installation In Redhat And CentOS
 
Docker
 
Run the below command to add docker repo.
 
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:
 
subscription-manager repos --enable=rhel-7-server-extras-rpms
 
Kubernetes Installation In Redhat And CentOS
 
You can see all the steps so far in the below snap.
 
Kubernetes Installation In Redhat And CentOS
 
Step 8 - To install the docker and Kubernetes components
 
Run the following command to install the Kubenetes / Docker (kublet kubeadm kubectl docker)
 
yum install kubelet kubeadm kubectl docker -y
 
Kubernetes Installation In Redhat And CentOS
 
Step 9 - To start and enable Kubernetes and docker services
 
Run the below commands to start.
 
systemctl start docker && systemctl enable docker
 
Kubernetes Installation In Redhat And CentOS
 
systemctl start kubelet && systemctl enable kubelet
 
Kubernetes Installation In Redhat And CentOS
 
Step 10 -To run cluster configuration in Master node, this step should be followed only in master node
 
Run the below command to start cluster configuration in master node.
 
kubeadm init --apiserver-advertise-address=10.1.5.46 --ignore-preflight-errors all --pod-network-cidr=10.244.0.0/16 --token-ttl 0 
 
The apiserver address must be masternode IP (10.1.5.46) address.
 
You can see the below output:
 
Kubernetes Installation In Redhat And CentOS
 
After the successful start of kubadm master, we need to run the above-shown command from the non-root or root user. Only then can users control the kubectl commands.
 
Run the command.
 
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
 
Kubernetes Installation In Redhat And CentOS
 
Run the command
 
sudo chown $(id -u):$(id -g) $HOME/.kube/config
 
Kubernetes Installation In Redhat And CentOS
 
Step 11 - To check the all pods are running successful in cluster
 
Run the command and you can see all pods in namespaces.
 
kubectl get pods –all-namespaces
 
Kubernetes Installation In Redhat And CentOS
 
You can see the coredns service has not yet started, it's stiill pending. So for that we need to install a 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 a pod network
 
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
 
Kubernetes Installation In Redhat And CentOS
 
Now you can see coredns and all pods in namespaces are in ready mode and running successfully.
 
Kubernetes Installation In Redhat And CentOS
 
Step 13 - To taint master node as a Master
 
Run the below command to taint the master node and make it a master.
 
kubectl taint nodes --all node-role.kubernetes.io/master-
 
Kubernetes Installation In Redhat And CentOS
 
Step 14 - Join the Worker Nodes to Master Node.
 
Run the token which was produced by master node in other nodes to join to the cluster.
 
Kubernetes Installation In Redhat And CentOS 
 
Generated Token
 
kubeadm join 10.1.5.46:6443 –token lixbn2.aea4n63ypd42578
 
Kubernetes Installation In Redhat And CentOS
 
Run the command to check if all the nodes are connected to cluster or not.
 
Kubectl get nodes
 
Kubernetes Installation In Redhat And CentOS 
 
Step 15 - To Install and configure Kubernetes Dashboard
 
Run the below command to install the dashboards.
 
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta8/aio/deploy/recommended.yaml
 
Kubernetes Installation In Redhat And CentOS
 
Create a service account dashboard(username) for dashboard to access it
 
kubectl create serviceaccount dashboard -n default
 
Kubernetes Installation In Redhat And CentOS
 
Run the below command to give admin access to user (dashboard) to bind with cluster for accessing dashboard.
 
kubectl create clusterrolebinding dashboard-admin -n default --clusterrole=cluster-admin --
serviceaccount=default:dashboard
 
Kubernetes Installation In Redhat And CentOS
 
Run the below command to generate the secret key for user (dashboard), to access Kubernetes dashboard.
 
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.
 
Kubernetes Installation In Redhat And CentOS
 
To start the dashboard service, run the below command.
 
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/.
 
Kubernetes Installation In Redhat And CentOS
 
After signing in you can see the Kubernetes dashboard
 
Kubernetes Installation In Redhat And CentOS
 
In the end we completed our Kubernetes cluster configuration setup successfully.
 
I hope you love this article, please share and like it.


Similar Articles