How to Install Kubernetes 1.21 on CentOS 7 / RHEL 7
What is Kubernetes?
Kubernetes is a container management tool. It is Donated by Google to the Opensource community. It has now become the defacto container management tool of choice.
In Kubernetes setup we have one master (control) node and multiple worker nodes. The worker-nodes are then managed from the master node, thus ensuring that the cluster is managed from a central point.
You can also deploy a single-node Kubernetes cluster. You can use Minikube, which is a tool that runs a single-node Kubernetes cluster in a virtual machine on your node.
For this tutorial, we will walk-through a multi-node Kubernetes cluster installation based on CentOS 7 .
How to Install Kubernetes :
Prerequisites:
- Multiple servers running Centos 7 (1 Master Node, 2 Worker Nodes). It is recommended that your Master Node have at least 2 CPUs.
 - Internet connectivity on all your nodes. We will be fetching kubernetes and docker packages from the repository.
 - You will also need access to an account with sudo or root privileges. In this tutorial, I will be using my root account.
 
Installations Steps of Kubernetes 1.21 on Master Node
Setup Hostname, Firewall and SELinux
On your master node, set the hostname and if you don’t have a DNS server, then also update your /etc/hosts file.
Next, disable SElinux and update your firewall rules or disable your firewall.
Disable Swap in all nodes using “swapoff -a” command and remove or comment out swap partitions or swap file from fstab file.
Set the following firewall rules on ports.
Or you can Disable Firewall.
[root@devopszones ~]#systemctl disable firewalld
Add the Kubernetes Repo
You will need to add Kubernetes repositories manually as they do not come installed by default on CentOS 7.
Install Kubeadm and Docker
When the installation completes successfully, enable and start both the services.
Initialize Kubernetes Master
Initializing Kubernetes master is a fully automated process that is managed by the “kubeadm init“ command which you will run.
| Kubeadm init | 
As we can see in the output that kubernetes master has been initialized successfully. Execute the beneath commands to use the cluster as root user.
[root@devopszones ~]# mkdir -p $HOME/.kube
[root@devopszones ~]# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
[root@devopszones ~]# sudo chown $(id -u):$(id -g) $HOME/.kube/configDeploy a pod network to the cluster
To make the cluster status readyrunning, deploy the pod network so that containers of different host communicated each other. POD network is the overlay network between the worker nodes.
Run the Following command to deploy network.
[root@devopszones ~]#kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
serviceaccount/weave-net created
clusterrole.rbac.authorization.k8s.io/weave-net created
clusterrolebinding.rbac.authorization.k8s.io/weave-net created
role.rbac.authorization.k8s.io/weave-net created
rolebinding.rbac.authorization.k8s.io/weave-net created
daemonset.apps/weave-net created
[root@devopszones ~]#[root@devopszones ~]#kubectl get pods -A
NAMESPACE     NAME                                 READY   STATUS    RESTARTS   AGE
kube-system   coredns-558bd4d5db-4c6d7             1/1     Running   0          5m5s
kube-system   coredns-558bd4d5db-d7995             1/1     Running   0          5m5s
kube-system   etcd-kubemaster                      1/1     Running   0          5m2s
kube-system   kube-apiserver-kubemaster            1/1     Running   0          5m11s
kube-system   kube-controller-manager-kubemaster   1/1     Running   0          5m10s
kube-system   kube-proxy-qg4js                     1/1     Running   0          5m5s
kube-system   kube-scheduler-kubemaster            1/1     Running   0          5m2s
kube-system   weave-net-skv44                      2/2     Running   0          21s
[root@devopszones ~]#
[root@devopszones ~]#kubectl get nodes
NAME          STATUS     ROLES                  AGE     VERSION
kubemaster    Ready      control-plane,master   6m57s   v1.21.3
Setting Up Worker Nodes to Join Kubernetes Cluster
Setup Hostname, Firewall and SELinux
On your master node, set the hostname and if you don’t have a DNS server, then also update your /etc/hosts file.
Next, disable SElinux and update your firewall rules or disable your firewall.
Disable Swap in all nodes using “swapoff -a” command and remove or comment out swap partitions or swap file from fstab file.
Set the following firewall rules on ports.
Or you can Disable Firewall.
[root@devopszones ~]#systemctl disable firewalld
Add the Kubernetes Repo
You will need to add Kubernetes repositories manually as they do not come installed by default on CentOS 7.
Install Kubeadm and Docker
When the installation completes successfully, enable and start both the services.
Join the Worker Node to the Kubernetes Cluster
We now require the token that kubeadm init generated, to join the cluster. You can copy and paste it to your kubeworker1 and kubeworker2 if you had copied it somewhere.
| Kubernetes worker node join | 
[root@devopszones ~]#kubectl get nodes
NAME          STATUS   ROLES                  AGE   VERSION
kubemaster    Ready    control-plane,master   72m   v1.21.3
kubeworker1   Ready    <none>                 66m   v1.21.3
kubeworker2   Ready    <none>                 64m   v1.21.3
[root@devopszones ~]#
Disable SELINUX? Not a good idea folks. Just sayin'
ReplyDelete