Skip to content
LF Cert Trainer

Lesson 64 · Section 6: Cluster Maintenance

Lesson 64: Cluster upgrade introduction: version skew, order and strategy

How a Kubernetes cluster moves to a new version without stopping: which components may run at different versions, why the control plane goes first, the three ways to upgrade worker nodes, and the kubeadm steps you repeat on every node. · 18 min read · 5 min video

1/11Cluster upgrade introduction
0:00 / 4:46

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

What a cluster upgrade is

Kubernetes releases a new minor version about three times a year, and only the newest three minor versions receive bug and security fixes. A cluster that is never upgraded is out of support within about a year. Upgrading is therefore routine work for an administrator, and a regular task in the CKA exam.

A cluster is not one program with one version. It is a set of components spread over several machines:

  • on the control plane: kube-apiserver, kube-controller-manager, kube-scheduler and etcd
  • on every node: kubelet and kube-proxy
  • on your side: kubectl, and kubeadm as the tool that performs the upgrade
  • add-ons that live in the cluster: CoreDNS and the network (CNI) plugin

You cannot replace all of these in the same second, and you would not want to, because that would stop every application. An upgrade is a sequence: one component after another, one node after another, while the cluster keeps working. For a while the components run at different versions. The whole design of an upgrade answers one question: which mixtures of versions are allowed?

This lesson explains the rules and the plan. The previous lessons covered the two things it builds on: taking a node out of service with drain, cordon and uncordon (OS Upgrades), and how versions are numbered and supported (Kubernetes Releases). The next lesson runs the complete upgrade on a cluster, command by command.

How it works

Version skew: who may differ from whom

The allowed difference between component versions is called version skew. The Kubernetes project publishes it as a policy, and it is the same for every release.

How far each component may differ from the API server1 behind3 behind1 either waykube-apiserver1.37Controllers, scheduler1.37 or 1.36kubelet, kube-proxy1.37 down to 1.34kubectl1.36, 1.37 or 1.38
How far each component may differ from the API server. The API server sets the pace. Nothing in the cluster may be newer than it, and each component has its own limit for how far it may fall behind. Only kubectl may be one version ahead.

Parts:

  • kube-apiserver (1.37)
  • Controllers, scheduler (1.37 or 1.36)
  • kubelet, kube-proxy (1.37 down to 1.34)
  • kubectl (1.36, 1.37 or 1.38)

Connections:

  • kube-apiserver to Controllers, scheduler: 1 behind
  • kube-apiserver to kubelet, kube-proxy: 3 behind
  • kube-apiserver to kubectl: 1 either way

With kube-apiserver at 1.37:

ComponentAllowed versionsRule
kube-apiserver1.37The reference. In a cluster with several API servers, they may differ by one minor version among themselves
kube-controller-manager, kube-scheduler1.37, 1.36Not newer than the API server, at most one minor version older
kubelet, kube-proxy1.37, 1.36, 1.35, 1.34Not newer than the API server, at most three minor versions older
kubectl1.38, 1.37, 1.36One minor version newer or older

Three things in this table are worth understanding, not only memorising.

Why nothing may be newer than the API server. Every component is a client of the API server. A newer client may ask for an API or a field that the older server has never heard of. An older client, on the other hand, only uses things the server already knows, because Kubernetes keeps old APIs working for several releases. So "server first, clients after" is always safe, and the reverse is not.

Why kubectl is the exception. kubectl is the one client that lives outside the cluster, on laptops you do not control. Allowing it to be one version ahead or behind means that an administrator can upgrade their own tool before or after the cluster, and one kubectl can work with clusters on neighbouring versions.

Why the kubelet gets three versions of room. There are many nodes and upgrading each one means moving workloads. The wide limit lets you upgrade the control plane several times before you have to touch every node. It is room to breathe, not a target: a kubelet that is already three versions behind must be upgraded before the control plane can move again.

One minor version at a time

You can go from any patch version to any later patch version in one step: 1.36.1 to 1.36.5, or 1.36.5 straight to 1.37.2. You cannot skip a minor version. Going from 1.35 to 1.37 means two upgrades:

1.35.x  ->  1.36.x  ->  1.37.x

The reason is how APIs are retired. A feature is first deprecated and then removed some releases later, and each release contains the code that converts stored objects from the old form to the new one. If you jump over a release, you jump over its conversion step. kubeadm enforces the rule: it refuses an upgrade that skips a minor version.

This is also why falling far behind is expensive. A cluster on 1.33 that must reach 1.37 needs four full upgrades in a row.

The order: control plane first

Because nothing may be newer than the API server, the order is fixed:

  1. Control plane components. kube-apiserver first, then kube-controller-manager and kube-scheduler (in any order). With kubeadm, one command does all of this.
  2. Kubelets, node by node, including the kubelet on the control plane node itself.
  3. kubectl and other clients, whenever it suits you, as long as they stay within one minor version.
The order of a kubeadm upgradeplanthenworkers nextemptyReadyUpgrade kubeadmcontrol plane nodekubeadm upgrade applycontrol plane PodsUpgrade kubeletdrain, restart, uncordonDrain workerPods move awaykubeadm upgrade nodethen kubelet, restartUncordon workernext worker
The order of a kubeadm upgrade. Control plane first, workers after. On every node the tool comes first, then the node's configuration, and the kubelet last.

Parts:

  • Upgrade kubeadm (control plane node)
  • kubeadm upgrade apply (control plane Pods)
  • Upgrade kubelet (drain, restart, uncordon)
  • Drain worker (Pods move away)
  • kubeadm upgrade node (then kubelet, restart)
  • Uncordon worker (next worker)

Connections:

  • Upgrade kubeadm to kubeadm upgrade apply: plan
  • kubeadm upgrade apply to Upgrade kubelet: then
  • Upgrade kubelet to Drain worker: workers next
  • Drain worker to kubeadm upgrade node: empty
  • kubeadm upgrade node to Uncordon worker: Ready

Between step 1 and the end of step 2 the cluster runs in a mixed state, for example the API server on 1.37 and the kubelets on 1.36. That is fully supported. It is exactly the state the skew policy exists to allow.

What kubeadm does, and what it leaves to you

In the exam, and in most clusters you build yourself, the upgrade is done with kubeadm. It has three upgrade commands:

CommandWhereWhat it does
kubeadm upgrade planFirst control plane nodeChecks that the cluster can be upgraded and lists the versions you can reach. Changes nothing
kubeadm upgrade apply v1.37.xFirst control plane node, oncePulls the new images, rewrites the static Pod manifests for the API server, controller manager, scheduler and etcd, renews the cluster certificates, and upgrades the CoreDNS and kube-proxy add-ons
kubeadm upgrade nodeEvery other nodeOn another control plane node: upgrades its control plane Pods. On a worker: refreshes the local kubelet configuration

Three pieces are not handled by any of these commands:

  • The kubeadm binary. It is an operating system package, and the version of the binary decides which version it can upgrade to. You upgrade the package first, on each node, before you run kubeadm upgrade there.
  • The kubelet and kubectl. Also packages. kubeadm upgrade plan reminds you: it lists the kubelet under "components that must be upgraded manually". The kubelet is a system service, not a Pod, so a new package only takes effect after systemctl restart kubelet.
  • The CNI plugin. Calico, Cilium, Flannel and the others have their own upgrade instructions.

The package repository is per minor version

The Kubernetes packages come from pkgs.k8s.io, and each minor version has its own repository. A node that was installed for 1.36 only sees 1.36 packages, however often you run apt-get update. Before a minor upgrade you switch the repository on every node:

# /etc/apt/sources.list.d/kubernetes.list
deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.37/deb/ /

Change v1.36 to v1.37 in that line, run sudo apt-get update, and the new packages appear. A patch upgrade inside the same minor version needs no change. Forgetting this step is the most common reason for "the version I need is not available".

What the applications notice

While the control plane is upgraded. With a single control plane node, the API server restarts and is unreachable for a short time. Running Pods are not affected: the kubelet and the container runtime keep the containers alive, and kube-proxy's rules keep Services working. What stops is management. kubectl gets no answer, no Pod is scheduled, no Deployment is scaled, and a Pod that crashes is not replaced by its controller until the control plane is back. In a cluster with three control plane nodes you upgrade them one at a time and the API stays available throughout.

While a worker is upgraded. Draining the node evicts its Pods. Pods that belong to a Deployment, ReplicaSet or StatefulSet are created again on other nodes. A bare Pod with no controller is simply gone, which is why drain refuses to delete one unless you pass --force. For a minor version upgrade the node must be drained first: upgrading the kubelet across minor versions with Pods still running on it is not supported.

Three strategies for the worker nodes

Three ways to upgrade the worker nodesWorkers on 1.36control plane on 1.37All at onceevery node togetherOne at a timedrain, upgrade, uncordonReplace nodesadd new, remove oldDowntimeno Pod is runningNo downtimeone node less capacityNo downtimefull capacity kept
Three ways to upgrade the worker nodes. All three end with every node on the new version. They differ in what the applications feel while it happens, and in how much spare capacity you need.

Parts:

  • Workers on 1.36 (control plane on 1.37)
  • All at once (every node together)
  • One at a time (drain, upgrade, uncordon)
  • Replace nodes (add new, remove old)
  • Downtime (no Pod is running)
  • No downtime (one node less capacity)
  • No downtime (full capacity kept)

Connections:

  • Workers on 1.36 to All at once
  • Workers on 1.36 to One at a time
  • Workers on 1.36 to Replace nodes
  • All at once to Downtime
  • One at a time to No downtime
  • Replace nodes to No downtime
StrategyHowApplicationsNeeds
All at onceUpgrade every worker togetherDown until the nodes are backNothing extra. Acceptable for a test cluster only
One at a time (rolling)Drain, upgrade, uncordon, next nodeStay up, on the remaining nodesEnough spare capacity to run without one node
Replace the nodesAdd nodes with the new version, drain and delete the old onesStay up, at full capacityThe ability to create machines quickly: a cloud, or a node pool

The rolling strategy is the one kubeadm's documentation describes and the one the exam expects. Replacing nodes is what managed services such as GKE, EKS and AKS do for you when you upgrade a node pool: there the provider upgrades the control plane at the press of a button, and you never run kubeadm at all.

Under the hood · Clusters with several control plane nodes

In a highly available cluster the control plane nodes are upgraded one after another, and the skew policy has an extra clause for the time in between: API servers may differ from each other by at most one minor version.

  • On the first control plane node: upgrade kubeadm, run kubeadm upgrade plan, then kubeadm upgrade apply v1.37.x.
  • On each further control plane node: upgrade kubeadm, then run kubeadm upgrade node. No version argument and no plan are needed, because the target is already recorded in the cluster.
  • Then upgrade the kubelet on each of them.

While two API server versions are running, the limits for everyone else narrow: the controller manager, scheduler and kubelets must not be newer than the oldest API server. That is another reason to finish all API servers before touching anything else. Recent kubeadm versions follow the same logic for add-ons: CoreDNS and kube-proxy are only upgraded once every control plane node is on the new version.

Using it

Example · Find out where the cluster is and where it can go

Three commands give you the starting point:

kubectl get nodes                 # VERSION = kubelet version per node
kubectl version                   # Server Version = kube-apiserver
kubeadm version -o short          # the upgrade tool itself
NAME           STATUS   ROLES           AGE   VERSION
controlplane   Ready    control-plane   90d   v1.36.3
node01         Ready    <none>          90d   v1.36.3
node02         Ready    <none>          90d   v1.36.3

To see which versions are on offer, ask the package manager (after switching the repository to the new minor version) and then ask kubeadm:

sudo apt-get update
apt-cache madison kubeadm         # lists package versions such as 1.37.0-1.1
sudo kubeadm upgrade plan

kubeadm upgrade plan prints the current and target version of every control plane component, the kubelets it found, and the exact kubeadm upgrade apply command to run. It can only offer versions up to its own, so if the plan does not show the version you want, the kubeadm package is still the old one.

Example · Upgrade the control plane node from 1.36 to 1.37

All commands run on the control plane node. First the tool:

# switch the repository line from v1.36 to v1.37, then:
sudo apt-mark unhold kubeadm
sudo apt-get update && sudo apt-get install -y kubeadm='1.37.0-*'
sudo apt-mark hold kubeadm
kubeadm version -o short          # v1.37.0

Then the control plane components:

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

At this point kubectl version reports the server on 1.37, but kubectl get nodes still shows v1.36.3 for the node, because the kubelet has not changed. Finish the node:

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

The packages are kept on hold so that an ordinary apt-get upgrade never moves Kubernetes to a new version by accident. That is why each step unholds, installs and holds again.

Example · Upgrade one worker node

Draining and uncordoning are kubectl commands, so they run where kubectl is configured, usually the control plane node. Everything in between runs on the worker.

# on the control plane node
kubectl drain node01 --ignore-daemonsets

# on node01 (ssh node01), after switching the repository line to v1.37
sudo apt-mark unhold kubeadm kubelet
sudo apt-get update && sudo apt-get install -y kubeadm='1.37.0-*'
sudo kubeadm upgrade node
sudo apt-get install -y kubelet='1.37.0-*'
sudo apt-mark hold kubeadm kubelet
sudo systemctl daemon-reload
sudo systemctl restart kubelet
exit

# back on the control plane node
kubectl uncordon node01
kubectl get nodes
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.36.3

Repeat for node02. Draining one worker at a time means the other workers must have room for its Pods. Check with kubectl get pods -A -o wide after the drain that everything found a new home before you continue.

Example · Plan an upgrade for a cluster that fell behind

A cluster reports this:

Server Version: v1.35.4
NAME           STATUS   ROLES           VERSION
controlplane   Ready    control-plane   v1.35.4
node01         Ready    <none>          v1.33.6
node02         Ready    <none>          v1.33.6

The goal is 1.37 everywhere. Work it out from the rules:

  1. The control plane cannot jump from 1.35 to 1.37. It must go to 1.36 first.
  2. With the API server on 1.36, the kubelets on 1.33 are three versions behind. That is still allowed.
  3. With the API server on 1.37, kubelets on 1.33 would be four behind. Not allowed. The workers must move before the second control plane upgrade.

A valid plan:

control plane 1.35 -> 1.36
workers       1.33 -> 1.34 -> 1.35 -> 1.36     (one node at a time)
control plane 1.36 -> 1.37
workers       1.36 -> 1.37

The workers take one minor version per step as well, each step with kubeadm upgrade node and a kubelet restart. It is long, and that is the argument for upgrading regularly instead.

Tricks

Common mistakes

  • Reading the cluster version from kubectl get nodes. That column is the kubelet. The API server's version is Server Version in kubectl version.
  • Trying to skip a minor version. 1.35 to 1.37 in one step is refused. Go through 1.36.
  • Upgrading a kubelet before the control plane. A kubelet newer than the API server breaks the skew policy. Control plane first, always.
  • Not switching the package repository. Each minor version has its own repository on pkgs.k8s.io. Without the change, apt only offers the old minor version.
  • Running kubeadm upgrade apply with the old kubeadm. The binary can only upgrade to its own version. Upgrade the kubeadm package first and confirm with kubeadm version.
  • Forgetting to restart the kubelet. Installing the package replaces the file on disk; the running process is still the old one until systemctl daemon-reload and systemctl restart kubelet.
  • Forgetting to uncordon. The node stays Ready,SchedulingDisabled and receives no new Pods. In the exam the task is not complete.
  • Upgrading more than the task says. If the task names only the control plane node, leave the workers alone.

Recap

  • An upgrade is a sequence, so components run at different versions for a while. The version skew policy says which mixtures are allowed.
  • With the API server at X: controller manager and scheduler X or X-1, kubelet and kube-proxy X to X-3, kubectl X-1 to X+1. Nothing but kubectl may be newer than the API server.
  • Upgrade one minor version at a time. Patch versions can be skipped freely.
  • Order: control plane first, then the nodes one by one, with drain before and uncordon after.
  • kubeadm: upgrade plan to check, upgrade apply <version> once on the first control plane node, upgrade node on every other node. The kubeadm, kubelet and kubectl packages are upgraded by you, and the kubelet needs a restart.
  • While a single control plane restarts, applications keep running but nothing can be managed. Workers are upgraded all at once, one at a time, or by replacing them with new nodes.

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

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

  • 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.