0
0
Kubernetesdevops~10 mins

Cluster upgrade strategies in Kubernetes - Commands & Configuration

Choose your learning style9 modes available
Introduction
Upgrading a Kubernetes cluster means updating its software to a newer version. This keeps the cluster secure, stable, and able to use new features. Doing this without breaking running applications is the main challenge.
When a new Kubernetes version is released with important security fixes.
When you want to use new Kubernetes features that require a newer version.
When your current cluster version is no longer supported by your cloud provider.
When you need to fix bugs or improve performance in your cluster.
When preparing your cluster to support newer versions of your applications.
Commands
This command safely evicts all pods from node-1 so it can be upgraded without affecting running applications. It ignores daemonsets and deletes local data to avoid blocking.
Terminal
kubectl drain node-1 --ignore-daemonsets --delete-local-data
Expected OutputExpected
node/node-1 cordoned pod/my-app-1234 evicted pod/my-app-5678 evicted node/node-1 drained
--ignore-daemonsets - Allows draining even if daemonset pods are present on the node.
--delete-local-data - Deletes pods with local data to avoid blocking the drain.
This command upgrades the Kubernetes control plane to version 1.27.3. It updates the master components safely.
Terminal
sudo kubeadm upgrade apply v1.27.3
Expected OutputExpected
[upgrade] Making sure the cluster is healthy: [upgrade] Upgrading your Static Pod-hosted control plane to version "v1.27.3" [upgrade] Successfully upgraded control plane.
This command marks node-1 as schedulable again so it can run pods after the upgrade is complete.
Terminal
kubectl uncordon node-1
Expected OutputExpected
node/node-1 uncordoned
This command lists all nodes and their status to verify the upgrade was successful and nodes are ready.
Terminal
kubectl get nodes
Expected OutputExpected
NAME STATUS ROLES AGE VERSION node-1 Ready control-plane 10d v1.27.3 node-2 Ready <none> 10d v1.27.3
Key Concept

If you remember nothing else from this pattern, remember: drain nodes before upgrading and uncordon them after to keep your cluster stable.

Common Mistakes
Upgrading nodes without draining them first
This causes running pods to be disrupted and can lead to downtime or data loss.
Always run 'kubectl drain' on a node before upgrading it to safely move pods away.
Forgetting to uncordon nodes after upgrade
Nodes remain unschedulable and new pods will not be placed on them, reducing cluster capacity.
Run 'kubectl uncordon' after upgrading to allow pods to be scheduled again.
Not verifying node versions after upgrade
You might think the upgrade succeeded but nodes could still be running old versions.
Use 'kubectl get nodes' to check the version and status of all nodes after upgrade.
Summary
Drain nodes to safely evict pods before upgrading.
Use kubeadm to upgrade the control plane to the desired Kubernetes version.
Uncordon nodes after upgrade to resume scheduling pods.
Verify node status and versions to confirm successful upgrade.