How to Add Node to Existing Kubernetes Cluster
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
- Once reviewed get kubeadm to join the command from the below command and copy it down.
kubeadm token create --print-join-command
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
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
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
- Finally install kubelet , kubeadm & kubectl
apt-get install -y kubelet kubeadm kubectl
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.
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
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.