How to install kubernetes cluster on centos 7

In this tutorial, we will explore how to install Kubernetes cluster from scratch. Kubernetes is the most popular container Orchestration engine. Kubernetes cluster can be deployed with one master and one worker node or multiple master and multiple worker nodes. Here will will deploy one master and two worker node setup. Since we are deploying 3 node cluster, we will need 3 servers with centos 7 installed on it.

kubernetes cluster

Prerequisites

  1. Master node should have at least 2GB of ram so that it can run smoothly without glitches.
  2. All the servers should have networking configured and should be able to communicate with each other. We are having 3 servers with below IP configuration
  • Master: 192.168.136.133 -> master.onehalt.in
  • Node1: 192.168.136.134 -> node1.onehalt.in
  • Node2: 192.168.136.135 -> node2.onehalt.in

Lets get our hands dirty

All the below steps need to be run / performed on all the 3 kubernetes nodes.

We need to add hostname entries to DNS server or we can use /etc/hosts for hostname to IP resolution. Add below entries on all the 3 servers.

# vi /etc/hosts

All the servers should be able to ping each other.

Kubernetes ping

Next we need to disable Selinux, this can be done temporarily by using below command or can be done permanently by disabling in the selinux configuration.

#setenforce 0
#vi /etc/sysconfig/selinux
Kubernetes Selinux

For Kubernetes to work smoothly, lets disable swap

# swapoff -a

Since Kubernetes repository is now available for centos, we will configure yum to use the same.

#cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[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
EOF

Installing kubeadm and docker

We will be installing the most popular container engine platform that is docker in this tutorial. Once kubeadm and docker are installed, we need to enable both the services so that they can start automatically on reboot and start.

#yum install kubeadm docker -y
#systemctl enable kubelet
#systemctl start kubelet
#systemctl enable docker
#systemctl start docker
kubernetes service

Configure Firewalld

We can disable firewalld on all the Kubernetes nodes or if you have an active firewalld, below firewalld rules needs to be enabled on Master and Worker nodes.

#systemctl disable --now firewalld  ##disable firewalld

Ports needs to be allowed on Kubernetes Master node

#firewall-cmd --add-port={6443,2379-2380,10250,10251,10252,5473,179,5473}/tcp --permanent
#firewall-cmd --add-port={4789,8285,8472}/udp --permanent
#firewall-cmd --reload
#modprobe br_netfilter
#echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables

Ports needs to be allowed on Kubernetes Worker nodes

sudo firewall-cmd --add-port={10250,30000-32767,5473,179,5473}/tcp --permanent
sudo firewall-cmd --add-port={4789,8285,8472}/udp --permanent
sudo firewall-cmd --reload

Initializing Kubernetes Cluster Control plane

Lets initialize the kubernetes Control plane by running below command on the master node

#kubeadm init

Great, our Kubernetes control plane has been initialized successfully, Make sure you copy the kubeadm join command and keep it handy as this will be required to bootstrap or join our worker nodes with the control plane.

Joining worker node with control plane

Lets run below command on all the worker nodes to bootstrap.

kubeadm join 192.168.136.133:6443 --token ycg784.5bytqt60rub3ub05 \
        --discovery-token-ca-cert-hash sha256:04c6055419b8118f4f60011e2098f4f0757d570765c90e463dba0d093eb6d306

Lets setup the environment so that users can access this kubernetes cluster for performing various task. For accessing the Kubernetes cluster as root, run below commands

#mkdir -p $HOME/.kube
#cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
# chown $(id -u):$(id -g) $HOME/.kube/config

To use a sudo enabled user, run below commands

$sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$sudo  chown $(id -u):$(id -g) $HOME/.kube/config

Setting Up Pod network

Finally, we need to setup the pod networking by using CNI plugin. We will use Weavenet plugin in this tutorial for pod communication. Please refer link if you want to use some other cni plugins.

# export kubever=$(kubectl version | base64 | tr -d '\n')
# kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$kubever"
kubernetes cni

Now lets verify the kubernetes cluster from the master control plane using below command.

#kubect get nodes
kubernetes nodes

Conclusion

We have successfully created kubernetes cluster on centos 7 and we are able to see both the worker nodes with status as Ready.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments