How to Install Kubernetes on CentOS/RHEL k8s: Part-4

Now from the previous article, we have complete section1 for setting up Kubernetes cluster. In section 1 we have installed all the component and packages which were required to set up on both the worker node and master node.

We will be continuing our section 2 and section 3 in this article to complete our Kubernetes cluster. For those who have not completed section1 please follow this link to complete section 1 before continuing section 2:

How to Install Kubernetes on CentOS/RHEL

Before continuing section 2, I would like to mention about pod network. There are several pod network plugin available for communication between pods which is called by Kubernetes. Kubernetes supports the CNI – the Container Network Interface.

Following are few solutions which provide plugins for Kubernetes (listed alphabetically):

  • Calico
  • Flannel
  • Open vSwitch (OVS)
  • Romana
  • Weave
  • You can also write your own.

For this installation, I m going to use calico pod network. Well, you may use any of the pod network plugins to continue with the installation.

Section 2: Command to Run on Master Node only

Step 1: Initiate Kubernetes cluster

To initiate the pod network we need to run following command. In this comment, we will tell the kubernetes cluster to use pod network cidr and API server IP. As here I am initializing kubernetes cluster with calico pod network.

[root@kmaster ~]# kubeadm init --pod-network-cidr=192.168.0.0/16 --apiserver-advertise-address=192.168.56.101

This will take some time don’t worry after getting this complete, there are some important information keep it for further use like below
And keep kubeadm join command for future reference which will be used for joining your worker node.
kapendra.com_kubernets_install_successNow run the command as instructed from the result of the previous command.

[root@kmaster ~]# mkdir -p $HOME/.kube
[root@kmaster ~]# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
[root@kmaster ~]# sudo chown $(id -u):$(id -g) $HOME/.kube/config
Keep this for further use:
kubeadm join 192.168.56.101:6443 --token sr1t6u.gvdabpj1bjr2oruv --discovery-token-ca-cert-hash sha256:06186350f1f48466884b0a017f

Step 2: Bring UP the Pod (calico or flannel)

After kuberenets cluster initialization, we need to bring up the pod network so that our pods can communicate with each other.

[root@kmaster ~]# kubectl apply -f https://docs.projectcalico.org/v3.0/getting-started/kubernetes/installation/hosted/kubeadm/1.7/calico.yaml

kapendra.com_kubernets_install_calico

Test your calico pod network deployment.

[root@kmaster ~]# kubectl get pods -o wide --all-namespaces
kapendra.com_kubernets_install_all_pods
Bring Up the DashBoard
[root@kmaster ~]# kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
[root@kmaster ~]# kubectl get pods -o wide --all-namespaces

kapendra.com_kubernets_install_dashboard

Here comes the end of section 2 now we will run the last section i.e section3. In this section, we will run our command only on worker nodes.

Section 3: Command to Run on Worker Node only

Part 1: Join Node
Now run join command which we got after initialization of kubernetes cluster in section 2
On both

On Node 1

[root@knode1 ~]# kubeadm join 192.168.56.101:6443 --token sr1t6u.gvdabpj1bjr2oruv --discovery-token-ca-cert-hash sha256:06186350f1f48466884b0a017f

On Node 2

[root@knode2 ~]# kubeadm join 192.168.56.101:6443 --token sr1t6u.gvdabpj1bjr2oruv --discovery-token-ca-cert-hash sha256:06186350f1f48466884b0a017f

This Completes the installation process by joining our nodes. we can also verify that our nodes have joined kubernetes cluster by running on the master

[root@kmaster ~]# kubectl get nodes

In the next article, we will learn to set up minikube, a single node kubernetes setup for development and learning objective

Kubernetes Series Links:

Understanding Kubernetes Concepts RHEL/CentOs K8s Part-1
Understanding Kubernetes Concepts RHEL/CentOs k8s: Part-2
How to Install Kubernetes on CentOS/RHEL k8s?: Part-3
How to Install Kubernetes on CentOS/RHEL k8s?: Part-4
How To Bring Up The Kubernetes Dashboard? K8s-Part: 5
How to Run Kubernetes Cluster locally (minikube)? K8s – Part: 6
How To Handle Minikube(Cheatsheet)-3? K8s – Part: 7
How To Handle Minikube(Cheatsheet)-3? K8s – Part: 8
How To Handle Minikube(Cheatsheet)-3? K8s – Part: 9