Skip to content
LF Cert Trainer

Lesson 65 · Section 6: Cluster Maintenance

Lesson 65: Demo: upgrading a kubeadm cluster, node by node

A full walkthrough of a kubeadm upgrade from v1.36 to v1.37: the package repository, kubeadm upgrade plan and apply on the control plane, kubeadm upgrade node on the workers, drain, kubelet, uncordon, and how to check every step. · 20 min read · 4 min video

1/12Demo: cluster upgrade
0:00 / 4:05

Narrated by the local narrator voice. Keys: Space plays and pauses, J and L step, C captions, F full screen.

What this demo covers

The previous lesson explained the rules of a cluster upgrade: one minor version at a time, control plane before workers, and which components may run behind which. This lesson is the same upgrade with your hands on the keyboard. We take a small kubeadm cluster from v1.36.2 to v1.37.0 and look at the output of every command, so that you know what "worked" looks like before you meet the task in the exam.

The cluster has three Ubuntu nodes:

NAME           STATUS   ROLES           AGE   VERSION
controlplane   Ready    control-plane   90d   v1.36.2
node01         Ready    <none>          90d   v1.36.2
node02         Ready    <none>          90d   v1.36.2
The six steps on the control plane nodethenthenthenthenthen1. Package repopoint at v1.372. kubeadminstall 1.37.03. upgrade applycontrol plane Pods4. Drainevict the Pods5. kubeletinstall, restart6. UncordonReady, v1.37.0
The six steps on the control plane node. Read it as a loop: top row left to right, bottom row right to left. A worker node follows the same loop, with kubeadm upgrade node in place of kubeadm upgrade apply.

Parts:

  • 1. Package repo (point at v1.37)
  • 2. kubeadm (install 1.37.0)
  • 3. upgrade apply (control plane Pods)
  • 4. Drain (evict the Pods)
  • 5. kubelet (install, restart)
  • 6. Uncordon (Ready, v1.37.0)

Connections:

  • 1. Package repo to 2. kubeadm: then
  • 2. kubeadm to 3. upgrade apply: then
  • 3. upgrade apply to 4. Drain: then
  • 4. Drain to 5. kubelet: then
  • 5. kubelet to 6. Uncordon: then

How it works

Three tools take part, and each one upgrades a different thing. Most mistakes in this task come from expecting one tool to do another tool's job.

ToolWhat it upgradesWhat it leaves alone
Package manager (apt-get, dnf)The binaries on this machine: kubeadm, kubelet, kubectlEverything that runs as a Pod
kubeadm upgradeControl plane static Pods, etcd, CoreDNS, kube-proxy, certificates, kubelet configurationThe kubelet and kubectl binaries, the CNI plugin
kubectl drain and uncordonNothing. They move workloads away and let them come backAll versions
Which command upgrades which componentwritesrunsupdatesswapsshowskubeadm upgradeapply v1.37.0Static Pod files/etc/kubernetes/manifestsControl planeAPI server, etcd, ...Add-onsCoreDNS, kube-proxyapt-get installkubelet=1.37.0-*kubeletsystemd serviceVERSION columnkubectl get nodes
Which command upgrades which component. kubeadm upgrades everything that runs as a Pod. The kubelet is a system service, so only the package manager can replace it, and it is the kubelet's version that kubectl get nodes prints.

Parts:

  • kubeadm upgrade (apply v1.37.0)
  • Static Pod files (/etc/kubernetes/manifests)
  • Control plane (API server, etcd, ...)
  • Add-ons (CoreDNS, kube-proxy)
  • apt-get install (kubelet=1.37.0-*)
  • kubelet (systemd service)
  • VERSION column (kubectl get nodes)

Connections:

  • kubeadm upgrade to Static Pod files: writes
  • Static Pod files to Control plane: runs
  • kubeadm upgrade to Add-ons: updates
  • apt-get install to kubelet: swaps
  • kubelet to VERSION column: shows

kubeadm upgrades itself last, so you upgrade it first

kubeadm refuses to upgrade a cluster to a version newer than its own. The first package you install on every node is therefore the new kubeadm, and nothing else. Installing the new kubelet at the same moment is the classic slip: the kubelet would restart with a new version while the node is still full of running Pods and the API server is still old.

The packages are held (apt-mark hold) so that a routine apt-get upgrade never moves Kubernetes by accident. That is why every install line in this lesson has the same shape: unhold, install an exact version, hold again.

One repository per minor version

The community package repository at pkgs.k8s.io has a separate address for each minor version. A node installed for v1.36 only sees v1.36 packages:

deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.36/deb/ /

Until you change v1.36 to v1.37 in /etc/apt/sources.list.d/kubernetes.list, the package manager will tell you that version 1.37.0 does not exist. A patch upgrade (v1.37.0 to v1.37.3) stays inside one repository and skips this step. On RPM systems the same address lives in /etc/yum.repos.d/kubernetes.repo.

What kubeadm upgrade apply does

On the first control plane node, kubeadm upgrade apply v1.37.0 runs through a fixed list:

  1. Checks that the cluster is healthy, that all nodes are Ready, and that the version jump is allowed.
  2. Pulls the new control plane images.
  3. Rewrites the static Pod manifests in /etc/kubernetes/manifests, one component at a time: etcd, kube-apiserver, kube-controller-manager, kube-scheduler. The kubelet sees each changed file and restarts that Pod. If a component does not come back healthy, kubeadm puts the old manifest back.
  4. Renews the certificates it manages on this node.
  5. Updates the add-ons, CoreDNS and kube-proxy, and the cluster's stored kubeadm and kubelet configuration.

It keeps a backup of the old manifests and of the etcd data under /etc/kubernetes/tmp while it works. The command is also safe to run again: if it stops halfway, fix the cause and repeat it.

What it does not touch is the kubelet binary. The kubelet is a systemd service that starts the static Pods, so it cannot be replaced by one of them.

What kubeadm upgrade node does

On every other node there is nothing left to decide, so the command takes no version:

  • On a worker, it downloads the cluster's current kubelet configuration and writes it to /var/lib/kubelet/config.yaml. That is all.
  • On an additional control plane node, it does the same and also upgrades that node's own static Pods to the version the first node already chose.

Why kubectl get nodes still shows the old version

Right after a successful kubeadm upgrade apply, the node list has not changed:

NAME           STATUS   ROLES           AGE   VERSION
controlplane   Ready    control-plane   90d   v1.36.2

Nothing is wrong. The VERSION column is the version the kubelet on each node reports. The API server is already new, which you can see with kubectl version:

Client Version: v1.36.2
Server Version: v1.37.0

The column changes when you install the new kubelet package and restart the service.

Why drain, and why one node at a time

Restarting the kubelet does not kill running containers, so a drain is not strictly needed for the restart itself. It is there to make the upgrade boring: the node is empty while its kubelet changes version, and if anything goes wrong, no application is on it. kubectl drain does two things, in order. It cordons the node (no new Pods), then evicts the Pods so that their Deployments recreate them elsewhere.

One node at a timenextnextdrainmovedcontrolplanev1.37.0, donenode01drained, upgradingnode02v1.36.2, waitingEvicted Podsfrom node01New Podsrunning on node02
One node at a time. The control plane goes first. Each worker is then emptied, upgraded and put back before the next one starts, so the applications always have somewhere to run.

Parts:

  • controlplane (v1.37.0, done)
  • node01 (drained, upgrading)
  • node02 (v1.36.2, waiting)
  • Evicted Pods (from node01)
  • New Pods (running on node02)

Connections:

  • controlplane to node01: next
  • node01 to node02: next
  • node01 to Evicted Pods: drain
  • Evicted Pods to New Pods: moved

Draining two workers of three at once would leave one node to carry everything. Finish a node, see it Ready, then start the next.

Under the hood · How far behind may a node be?

The version skew policy sets the limits that make a rolling upgrade possible:

  • The kubelet must never be newer than the API server. It may be up to three minor versions older.
  • kube-controller-manager and kube-scheduler must not be newer than the API server, and may be one minor version older.
  • kubectl works within one minor version of the API server, older or newer.
  • kubeadm upgrades from one minor version to the next. Skipping a minor version is not supported, so v1.35 to v1.37 means two upgrades, with v1.36 in between.

This is why the control plane goes first and why the workers can follow later, even days later: an old kubelet talking to a new API server is a supported state. The reverse is not.

The walkthrough

Example · 1. Control plane: new repository, new kubeadm

On controlplane. Point the repository at the new minor version and find the exact package version:

sudo sed -i 's/v1.36/v1.37/' /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
apt-cache madison kubeadm
   kubeadm | 1.37.0-1.1 | https://pkgs.k8s.io/core:/stable:/v1.37/deb  Packages

Install that version of kubeadm only, and confirm it:

sudo apt-mark unhold kubeadm && \
sudo apt-get install -y kubeadm='1.37.0-*' && \
sudo apt-mark hold kubeadm

kubeadm version -o short        # v1.37.0

The -* at the end matches the package revision (-1.1), so you do not have to type it.

Example · 2. Control plane: plan, then apply

Still on controlplane. plan changes nothing. It checks the cluster and prints the command to run next:

sudo kubeadm upgrade plan
[upgrade/versions] Cluster version: 1.36.2
[upgrade/versions] kubeadm version: v1.37.0
[upgrade/versions] Target version: v1.37.0

Components that must be upgraded manually after you have upgraded the control plane with 'kubeadm upgrade apply':
COMPONENT   NODE           CURRENT   TARGET
kubelet     controlplane   v1.36.2   v1.37.0
kubelet     node01         v1.36.2   v1.37.0
kubelet     node02         v1.36.2   v1.37.0

Upgrade to the latest stable version:

COMPONENT                 NODE           CURRENT   TARGET
kube-apiserver            controlplane   v1.36.2   v1.37.0
kube-controller-manager   controlplane   v1.36.2   v1.37.0
kube-scheduler            controlplane   v1.36.2   v1.37.0
kube-proxy                               1.36.2    v1.37.0
...

You can now apply the upgrade by executing the following command:

	kubeadm upgrade apply v1.37.0

The output is shortened here. Notice the first table: kubeadm tells you itself that the kubelets are yours to upgrade. Now apply, with the version written out:

sudo kubeadm upgrade apply v1.37.0

kubeadm asks Are you sure you want to proceed? [y/N]; answer y, or add -y to the command. After a minute or two it ends with:

[upgrade] SUCCESS! A control plane node of your cluster was upgraded to "v1.37.0".

Check that the control plane really runs the new images:

kubectl -n kube-system get pods -l tier=control-plane \
  -o custom-columns=NAME:.metadata.name,IMAGE:.spec.containers[0].image
NAME                                   IMAGE
etcd-controlplane                      registry.k8s.io/etcd:...
kube-apiserver-controlplane            registry.k8s.io/kube-apiserver:v1.37.0
kube-controller-manager-controlplane   registry.k8s.io/kube-controller-manager:v1.37.0
kube-scheduler-controlplane            registry.k8s.io/kube-scheduler:v1.37.0

Example · 3. Control plane: drain, kubelet, uncordon

The node still reports v1.36.2, because its kubelet has not changed yet. Empty the node, replace the kubelet, and open the node again:

kubectl drain controlplane --ignore-daemonsets

sudo apt-mark unhold kubelet kubectl && \
sudo apt-get install -y kubelet='1.37.0-*' kubectl='1.37.0-*' && \
sudo apt-mark hold kubelet kubectl

sudo systemctl daemon-reload
sudo systemctl restart kubelet

kubectl uncordon controlplane
kubectl get nodes
NAME           STATUS   ROLES           AGE   VERSION
controlplane   Ready    control-plane   90d   v1.37.0
node01         Ready    <none>          90d   v1.36.2
node02         Ready    <none>          90d   v1.36.2

--ignore-daemonsets is needed on every real node: kube-proxy and the CNI plugin run as DaemonSet Pods, and drain refuses to continue while they are in its way unless you tell it to skip them. If the drain stops with "cannot delete Pods with local storage", add --delete-emptydir-data. The control plane is finished.

Example · 4. A worker: the same loop with kubeadm upgrade node

The worker has no admin kubeconfig, so kubectl commands run on controlplane and package commands run on the worker. Watch the prompt.

On node01 (reach it with ssh node01):

sudo sed -i 's/v1.36/v1.37/' /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update

sudo apt-mark unhold kubeadm && \
sudo apt-get install -y kubeadm='1.37.0-*' && \
sudo apt-mark hold kubeadm

sudo kubeadm upgrade node
[upgrade] The configuration for this node was successfully updated!
[upgrade] Now you should go ahead and upgrade the kubelet package using your package manager.

On controlplane:

kubectl drain node01 --ignore-daemonsets

On node01 again:

sudo apt-mark unhold kubelet kubectl && \
sudo apt-get install -y kubelet='1.37.0-*' kubectl='1.37.0-*' && \
sudo apt-mark hold kubelet kubectl

sudo systemctl daemon-reload
sudo systemctl restart kubelet
exit

Back on controlplane:

kubectl uncordon node01
kubectl get nodes               # node01: Ready, v1.37.0

Repeat the four blocks for node02, and only after node01 is Ready.

Example · 5. Check the whole cluster

An upgrade is finished when three things are true:

kubectl get nodes                       # every node Ready, v1.37.0, no SchedulingDisabled
kubectl get pods -A | grep -v Running   # nothing stuck, apart from Completed Jobs
kubectl version                         # client and server both v1.37.0
NAME           STATUS   ROLES           AGE   VERSION
controlplane   Ready    control-plane   90d   v1.37.0
node01         Ready    <none>          90d   v1.37.0
node02         Ready    <none>          90d   v1.37.0

One thing kubeadm never upgrades for you is the CNI plugin (Calico, Cilium, Flannel and so on). Check its documentation for the version that supports the new Kubernetes release and upgrade it the way it was installed.

When a step fails

What you seeCauseFix
E: Version '1.37.0-*' for 'kubeadm' was not foundThe repository file still points at v1.36Change the minor version in kubernetes.list, then apt-get update
kubeadm upgrade apply says the target version is higher than the kubeadm versionThe old kubeadm is still installedInstall the new kubeadm package first, then check kubeadm version
kubeadm upgrade plan offers only patch versions of v1.36Same cause: kubeadm itself is still v1.36Same fix
drain stops with "cannot delete DaemonSet-managed Pods"DaemonSet Pods cannot be evictedAdd --ignore-daemonsets
drain stops with "cannot delete Pods that declare no controller"A bare Pod would be lost for goodDecide: save it, or add --force and accept the loss
Node is Ready,SchedulingDisabled after the upgradeNobody uncordoned itkubectl uncordon with the node name
Node is NotReady after the kubelet restartThe kubelet is not runningsystemctl status kubelet, then journalctl -u kubelet for the reason
VERSION still shows v1.36.2 after installing the kubeletThe service still runs the old binarysudo systemctl daemon-reload && sudo systemctl restart kubelet

Tricks

Common mistakes

  • Installing kubelet together with kubeadm. The order is kubeadm, then kubeadm upgrade, then drain, then kubelet. Install only kubeadm in the first step.
  • Running kubeadm upgrade apply on a worker, or on a second control plane node. apply runs once, on the first control plane node. Every other node gets kubeadm upgrade node.
  • Forgetting the repository change. For a new minor version, the package cannot be found until the repository address names that version.
  • Forgetting to restart the kubelet. Installing the package replaces the file on disk. The running service keeps the old version until systemctl restart kubelet.
  • Forgetting to uncordon. The node looks healthy, runs the new version, and accepts no Pods.
  • Thinking apply failed because VERSION did not change. That column is the kubelet's version. Check the control plane with kubectl version or the images of the Pods in kube-system.
  • Trying to skip a minor version. kubeadm upgrades one minor version at a time. Repeat the whole procedure for each step.
  • Draining the next node too early. Wait until the upgraded node is Ready and uncordoned.

Recap

  • Order: first control plane node, any other control plane nodes, then the workers, one at a time.
  • On each node: repository to the new minor version, install kubeadm, run kubeadm upgrade, drain, install kubelet and kubectl, restart the kubelet, uncordon.
  • kubeadm upgrade plan checks and suggests; kubeadm upgrade apply v1.37.0 upgrades the control plane Pods, etcd, CoreDNS and kube-proxy; kubeadm upgrade node is for every other node and takes no version.
  • kubeadm never replaces the kubelet binary or the CNI plugin. The kubelet comes from the package manager.
  • kubectl get nodes shows kubelet versions, so it changes only after the kubelet restarts.
  • kubectl drain and uncordon run where kubectl works (the control plane); packages are installed on the node being upgraded.
  • Done means: every node Ready, on the target version, and schedulable.

Official docs

Quiz: check what you learned

5 questions on this lesson · about 3 min · instant feedback. Missed questions come back in your review queue.

Sign in to take the quiz and keep your score.

Practise: try it on a real cluster

2 hands-on labs for this lesson. You get goals, not steps: any solution that reaches them passes.

  • Section capstone on a kubeadm cluster. Empty a node for repair without hurting a protected app, save an etcd snapshot, unpack an older snapshot next to the live data, and upgrade the control plane node to the next Kubernetes version.

    Build · Level 3 · challenge · target 45 min

  • Upgrade a whole kubeadm cluster to the next minor version, control plane first and then the worker, with a drained node at each step and the shop running throughout.

    Build · Level 3 · challenge · target 40 min

Discussion

Learners ask and answer questions here. Sign in to read and join the discussion.