Upgrading Kubeadm Clusters From Scrach

Upgrading Kubeadm Clusters From Scrach

This blog explains how to upgrade a Kubernetes cluster created with kubeadm from version 1.25.7 to version 1.26.2

Before upgrading a cluster, make sure you read the release notes carefully.

The upgrade procedure on control plane nodes should be executed one node at a time. But in the upgrade, it's better to upgrade the control plane first and then worker nodes one by one.

Upgrade Control nodes:

Find the latest patch release for Kubernetes 1.26.2 using the OS package manager

sudo apt update
sudo apt-cache madison kubeadm
# find the latest 1.26.2 version in the list
# it should look like 1.26.2-00
  • Upgrade kubeadm
sudo apt-mark unhold kubeadm && \
sudo apt-get update && \
sudo apt-get install -y kubeadm=1.26.2-00 && \
sudo apt-mark hold kubeadm
  • Verify that the download works and has the expected version
kubeadm version
  • Verify the upgrade plan
kubeadm upgrade plan
  • Choose a version to upgrade to, and run the appropriate command
sudo kubeadm upgrade apply v1.26.2
  • Once the command finishes you should see

[upgrade/successful] SUCCESS! Your cluster was upgraded to "v1.26.2". Enjoy!

[upgrade/kubelet] Now that your control plane is upgraded, please proceed with upgrading your kubelets if you haven't already done so.

  • Prepare the node for maintenance by marking it un-schedulable and evicting the workloads
# replace <node-to-drain> with the name of your node you are draining
kubectl drain <node-to-drain> --ignore-daemonsets
  • Upgrade the kubelet and kubectl
sudo apt-mark unhold kubelet kubectl && \
sudo apt-get update && \
sudo apt-get install -y kubelet=1.26.2-00 kubectl=1.26.2-00 && \
sudo apt-mark hold kubelet kubectl
  • Restart the kubelet
sudo systemctl daemon-reload 
sudo systemctl restart kubelet
  • Bring the node back online by marking it schedulable
# replace <node-to-uncordon> with the name of your node
kubectl uncordon <node-to-uncordon>
  • Verify the status of the cluster
kubectl get nodes

Upgrade worker nodes

  • Upgrade kubeadm
# runs in worker nodes
sudo apt-mark unhold kubeadm && \
sudo apt-get update && \
sudo apt-get install -y kubeadm=1.26.2-00 && \
sudo apt-mark hold kubeadm
  • For worker nodes this upgrades the local kubelet configuration
# This would run in control node 
sudo kubeadm upgrade node
  • Prepare the node for maintenance by marking it un-schedulable and evicting the workloads
# replace <node-to-drain> with the name of your node you are draining
kubectl drain <node-to-drain> --ignore-daemonsets
  • Upgrade the kubelet and kubectl
# runs in worker nodes
sudo apt-mark unhold kubelet kubectl && \
sudo apt-get update && \
sudo apt-get install -y kubelet=1.26.2-00 kubectl=1.26.2-00 && \
sudo apt-mark hold kubelet kubectl
  • Restart the kubelet
sudo systemctl daemon-reload 
sudo systemctl restart kubelet
  • Bring the node back online by marking it schedulable
# replace <node-to-uncordon> with the name of your node
kubectl uncordon <node-to-uncordon>
  • Verify the status of the cluster
kubectl get nodes

Reference

Upgrading kubeadm clusters - kubernetes.io