Kubernetes is an open-source container orchestration tool developed by Google. In this article, you will learn how to set up Kubernetes with a master node and a worker node. Make sure you have Docker installed on both master and worker node.
Environment Details and Setup
For the demonstration, I have 2 Ubuntu systems, one will be the master node, and the other one will be the worker node. Both server configuration is as follows.
2 CPUs Master – 4 GB RAM / Worker – 2 GB RAM 10 GB Hard Disc
Use hostnamectl command to set the hostname on both the systems. On the Master Node: On Worker Node: So, below are the details of both nodes. Master Node
Hostname: kubernetes-master IP Address: 192.168.0.107
Worker Node
Hostname: kubernetes-worker IP Address: 192.168.0.108
Edit hosts file on both the systems. Before you start to install Kubernetes, run the below command on both master and worker nodes to check if Docker is up and running.
Install Kubernetes
Run all the commands mentioned in this section on both master and worker nodes. Firstly, add the Kubernetes package repository key. Run the command below to configure the Kubernetes package repository. Before proceeding ahead, disable swap on both the nodes.
Install Kubeadm
Now you need to install kubeadm. kubeadm is a tool in Kubernetes which is used to add nodes in the Kubernetes cluster. Check the kubeadm version to verify if it got installed correctly.
Initialize Kubernetes Cluster
Now, run the init command to initialize the Kubernetes cluster only on the master node. Use –apiserver-advertise-address to tell the worker node about the master’s IP address. To start using your cluster, you need to run the following as a regular user: Next, you need to deploy a pod network on the cluster. Run kubectl apply -f [podnetwork].yaml with one of the options listed at https://kubernetes.io/docs/concepts/cluster-administration/addons/ Then you can join any number of worker nodes by running the following on each as root: As mentioned in the output above, create .kube directory and copy admin.conf file to config file in .kube directory. At this moment, when you run the kubectl get nodes command, you will see the status of the master node is NotReady.
Deploy Pod Network – Flannel
Next, you need to deploy a pod network on the master node. I am using the Flannel pod network. It is used to communicate between nodes in the Kubernetes cluster. Check the status of the master node, it must be in Ready state. After a few seconds, check if all the pods are up and running.
Add Worker Node to the Cluster
Now that your master node is properly configured and running, its time to add the worker node. Here, you need to run the join command on the worker node, which you got after initializing kubeadm. Run the command below on the worker node to join the master node. On the Master Node: You will see a couple of more pods are running now after the worker node joined the cluster. Now, run the kubectl command again on the master node to check if the worker node has joined the cluster and it is running in the Ready state. Conclusion Now that the Kubernetes setup is ready, you can start orchestrating containers on the Kubernetes cluster. If Kubernetes thing excites you then you may want to learn by taking this Udemy course.