🗼Introduction
After successfully upgrading the control plane, the next crucial step is to upgrade the worker nodes. This ensures the entire cluster runs the same Kubernetes version, maintaining compatibility and stability. Below are detailed steps to upgrade the worker nodes in your Kubernetes cluster.
🗼Method 1: In-Place Upgrade
Step 1: Cordon the Node
First, prevent new pods from being scheduled on the node you are about to upgrade:
kubectl cordon <node-name>
Step 2: Drain the Node
Safely evict all pods from the node. This will gracefully terminate the pods and move them to other nodes:
kubectl drain <node-name> --ignore-daemonsets
Step 3: Upgrade Kubeadm on the Node
Upgrade kubeadm to the desired version on the node:
sudo apt-mark unhold kubeadm
sudo apt-get update
sudo apt-get install -y kubeadm=1.29.x-*
sudo apt-mark hold kubeadm
Step 4: Upgrade the Kubelet Configuration
Execute the kubeadm upgrade on the node to upgrade the kubelet configuration:
sudo kubeadm upgrade node
Step 5: Upgrade Kubelet and Kubectl
Upgrade kubelet and kubectl to the desired version:
sudo apt-mark unhold kubelet kubectl
sudo apt-get update
sudo apt-get install -y kubelet=1.29.x-* kubectl=1.29.x-*
sudo apt-mark hold kubelet kubectl
Step 6: Restart Kubelet
Restart the kubelet service to apply the upgrade:
sudo systemctl daemon-reload
sudo systemctl restart kubelet
Step 7: Uncordon the Node
Allow the node to accept new pods:
kubectl uncordon <node-name>
Repeat these steps for each worker node in the cluster.
🗼Method 2: Node Replacement (Ideal for Cloud Environments)
Step 1: Create a New Node
Provision a new node with the upgraded Kubernetes version.
Step 2: Join the New Node to the Cluster
Join the new node to the cluster using kubeadm join. You will need the token and hash from your cluster:
kubeadm join <control-plane-endpoint>:<port> --token <token> --discovery-token-ca-cert-hash sha256:<hash>
Step 3: Drain an Old Node
Drain the old node to safely evict all pods and move them to the new node:
kubectl drain <old-node-name> --ignore-daemonsets
Step 4: Delete the Old Node
Remove the old node from the cluster:
kubectl delete node <old-node-name>
Step 5: Repeat for Each Node
Repeat the process for each old node until all worker nodes have been replaced with upgraded ones.
🗼Conclusion
Upgrading worker nodes in a Kubernetes cluster ensures the entire environment is up-to-date and running smoothly. Whether you choose an in-place upgrade or replace nodes in a cloud environment, following these steps will help you maintain a stable and compatible Kubernetes cluster. Always remember to backup your data and perform upgrades in a controlled manner to minimize disruptions.