Kubernetes Cluster: Adding a node

My newfound love, Kubernetes or K8s (how its fondly known), has made my lazy weekends more meaningful. While I am at the very early stages of getting exposed to a production grade kubernetes environment, I continue to play around with the technology at every chance I get, with the least of resources I have managed to get access to.

Previously, I wrote about setting up a Kubernetes Cluster with Ubuntu machines. As a follow up to that, I would like to demonstrate how to add an other node to an existing cluster. Cluster information here:

Cluster Information

Preparing the node

The node I am going to use to demonstrate this would be: SS-UBUNTU02.

Prior to adding the node, I would like to show the status of kubelet service on the worker node (SS-UBUNTU03) that is already part of the cluster.

SS-UBUNTU03: Kubelet Status

And the status of the new node would be:

SS-UBUNTU02:Kubelet Status – Before

As part of the pre-requisites, I disabled the swap partition on this machine by commenting out the “fstab” entry and installed Kubeadm/Kubectl/Kubelet along with the container runtime (Docker). And to do so, as mentioned here, i used the following command:

sudo apt-get update && sudo apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
apt-get install docker.io

Once this is complete, the kubelet service status should now be running.

SS-UBUNTU02:Kubelet Status – After

Kubeadm Join Command

Now that the pre-reqs are completed, let us go back to the master node to add this newly deployed node as part of the kubernetes cluster. We will be using the Kubeadm utility to do this.

At the time of installation, during the cluster initialisation phase, kubeadm utility would have printed a command to standard output screen with which the worker node would have been made as a part of the cluster. This command did include a token generated for the master node which was set to expire in 24 hours. This leads us to create a new token which we will then use to join more nodes to the cluster.

To do this, we are going to use the kubeadm utility. The command below will create a token and will output the ca-cert-hash for the token, which is a mandatory flag to run the join command from the worker nodes.

kubeadm token create --print-join-command

Output of this command as shown below. Copy the output and run it from the node you intend to add to the cluster.

Kubeadm token create
kubeadm join <master-node-ip> --token <token-id> --discovery-token-ca-cert-hash <hash>

Executing the copied command from the new node:

SS-UBUNTU02: Join command

And finally on the worker node, we run:

kubectl get nodes -o wide
Get nodes

The difference in kubernetes client version that you see here on node2, is because I used the latest packages! This can be upgraded on the other nodes with a simple apt-get update/install.

PS: You should be able to find all of the aforementioned commands and procedure in the official kubernetes documentation here. This blog is just an attempt to give you the look and feel of how a K8s cluster and its nodes are bootstrapped.

Now that we have enough resources, let us go ahead and deploy our containers 🙂 To do so, what do we need next? I hear you. Images right? That’s what my next blog in this series is going to be about!

I would love to hear from you all what more would you like to see/read in this series!

Happy learning!!

Please follow and like my content:

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *

error

Enjoy this blog? Please spread the word :)