Open In App

How to Add Node to Existing Kubernetes Cluster

Last Updated : 26 Apr, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Kubernetes allows the management and orchestration of containerized deployments. We can use various cluster managing tools, but Kubeadm allows us to create and manage Kubernetes clusters from scratch. Kubernetes cluster can be autoscaled with the use of Cluster management services. In this article, we will see how we can manually add a node to an existing cluster.

Primary Terminologies

  • Kubernetes: It is an open-source container orchestration platform designed to automate the deployment, scaling, and management of containerized applications.
  • Kubernetes Cluster: It's a set of nodes on which containerized applications run.
  • Kubeadm: a Tool for creating and managing Kubernetes clusters.

Add new node to existing Kubernetes cluster

Step 1: View the existing cluster and get the kubeadm join command.

  • Go to the master node of the existing Kubernetes cluster and review its configuration.
  • View the existing nodes using the below command.
kubectl get nodes

oie_OAnmI7MizZam

  • Once reviewed get kubeadm to join the command from the below command and copy it down.
kubeadm token create --print-join-command

oie_5AICNUUSS59C

Step 2: Disable the firewall for the new node.

  • As we will be starting Kubernetes API server the firewall may interfere with our output. Hence disable the firewall using the below command.
sudo ufw disable
  • Then disable swapping for swapping devices using the below commands.
swapoff -a
sudo sed -i '/swap/d' /etc/fstab
  • Now we will add following parameters in kernel parameters. Run below command.
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
EOF

oie_tJo1PWCXKiBP-(1)

Step 3: Install the certificate applications.

  • Install the below applications with the help of below command.
sudo apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common

Step 4: Install Docker

  • Now lets install docker as root user . first switch to root user
sudo su
  • Add docker to apt list
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  • Update the apt
apt update
  • Finally install docker
apt install docker.io

oie_4ltUOveYd82R

Step 5: Install Kubernetes

  • Being as root add kubernetes keyrings using below command.
sudo mkdir -p -m 755 /etc/apt/keyrings
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
sudo chmod 644 /etc/apt/keyrings/kubernetes-apt-keyring.gpg
  • Add kubernetes list of packages to apt and allow required permissions.
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.29/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo chmod 644 /etc/apt/sources.list.d/kubernetes.list
  • Update the apt
apt update

oie_m5U0pD58LWPz

  • Finally install kubelet , kubeadm & kubectl
apt-get install -y kubelet kubeadm kubectl

oie_6ZxW7aA6wAk7

Step 6: Connect The new worker node.

  • On new worker node after following step 2 to 5 Run the kubeadm command copied from master node.
  • You should see that worker node has joined.

oie_M7wqwnta8S74

Step 7: Verify the cluster.

Now lets verify that new node has been added to the cluster.

  • On master node run Kubernetes commands to list all nodes.
kubectl get nodes

oie_KEbdTPl4P90Q

Conclusion

Thus we have seen how we can add a new node to the existing kubernetes cluster. This allows to autosclae kubernetes cluster manually from scratch allowing to manage each node separately. Like this we can add or remove nodes from cluster as requirement.


Next Article
Article Tags :

Similar Reads