Skip to content
Kubernetes day 2 · Chapter 7 of 20 Day 5: Upgrade plan and the way back

Day 5: Upgrade plan and the way back

Goal: Know what changes before the first upgrade, and have a tested way back in your pocket · Duration: approx. 45 min · Prerequisite: Days 1 to 4

Briefing

  • An upgrade without a way back is a bet. Here the way back means: an etcd snapshot and a copy of /etc/kubernetes, both stored outside the affected node.
  • The release notes of every minor version contain a section “Urgent Upgrade Notes”. You must have read what it says before the upgrade.
  • kubeadm upgrade plan shows what kubeadm would do. But it only knows versions up to its own.
  Before every upgrade (today)       Upgrade (Day 6–8)
  ┌──────────────────────────┐       ┌───────────────────────┐
  │ Inventory (Day 1)        │       │ Upgrade kubeadm       │
  │ pluto: 0 hits (Day 4)    │  ──▶  │ upgrade plan / apply  │
  │ PDBs: no 0 (Day 3)       │       │ kubelets, one node    │
  │ Changelog read           │       │ at a time             │
  │ etcd snapshot + copy     │       │ Add-ons               │
  └──────────────────────────┘       └───────────────────────┘

Drill 1: The Urgent Upgrade Notes

mkdir -p ~/day2/tag05 && cd ~/day2/tag05
curl -s https://raw.githubusercontent.com/kubernetes/kubernetes/master/CHANGELOG/\
CHANGELOG-1.36.md -o CHANGELOG-1.36.md
grep -n '^# v1.36.0' CHANGELOG-1.36.md

Expected:

813:# v1.36.0
1383:# v1.36.0-rc.1
1465:# v1.36.0-rc.0
1581:# v1.36.0-beta.0
1924:# v1.36.0-alpha.2
2106:# v1.36.0-alpha.1

What counts is the section from # v1.36.0 to the first pre-release. From it, the items where you have to act:

awk '/^# v1.36.0$/{f=1} /^# v1.36.0-rc/{f=0} f' CHANGELOG-1.36.md \
  | grep -o 'ACTION REQUIRED: [^.]*' | cut -c1-88

Expected:

ACTION REQUIRED: Plugins can opt-in to parallel execution by returning `AllowParallel: t
ACTION REQUIRED: DRA (Dynamic Resource Allocation) drivers and controllers now require g
ACTION REQUIRED: Removed the integrated support for flex-volumes in kubeadm
ACTION REQUIRED: Renamed metric `etcd_bookmark_counts` to `etcd_bookmark_total`

There is also a fifth occurrence that sits on a line of its own: the metric volume_operation_total_errors is now called volume_operation_errors_total. Assess every item for your cluster:

Item Does it affect the lab?
Scheduler plugins with PreBind no, no custom plugins
DRA drivers need finer-grained RBAC permissions no, no DRA
Flex volumes removed from kubeadm no
two renamed metrics yes, if dashboards or alerts use them

The renamed metrics are the typical silent damage: nothing breaks, but an alert never fires again because its metric no longer exists.

While skimming, also read the bug fixes. v1.36.0, for example, says:

grep -n 'pod lifecycle hooks' CHANGELOG-1.36.md | cut -c1-88

This affects your preStop hook from Day 3: hooks could run for their full duration when a Pod was terminated. After upgrading the kubelets on Day 7, you measure again whether anything changes in the result.

And one line about kubeadm itself that is easy to miss:

grep -m1 'ContainerRuntimeVersion' CHANGELOG-1.36.md | cut -c1-200 | fold -w 88

Expected:

- Kubeadm: The preflight check `ContainerRuntimeVersion` validates if the installed cont
ainer runtime supports the `RuntimeConfig` gRPC method. For older kubelet versions than
`v1.37`, it will return a preflight warning. ([#136898](https://github.com/kubernetes/ku

So for kubelets before v1.37 it is only a warning; after that, expect an abort. Whether your runtime supports RuntimeConfig is revealed by the kubelet log: the kubelet uses it to fetch the cgroup driver.

sudo journalctl -u kubelet --since today --no-pager \
  | grep -i 'cgroup driver setting received' | tail -1 | cut -c1-130

Expected:

Nov 21 19:04:04 cp1 kubelet[3426]: I1121 19:04:04.166883    3426 server.go:1418] "Using

The full line ends with "Using cgroup driver setting received from the CRI runtime" cgroupDriver="systemd". So containerd 2.2.1 supports the method. If this line is missing for you, update the runtime before the upgrade to v1.37. Lines like these make the difference between a calm upgrade and an aborted one.

Save your progress? Sign up for free

Drill 2: kubeadm upgrade plan – and its limit

sudo kubeadm upgrade plan

Expected (abridged):

[upgrade] Running cluster health checks
[upgrade] Fetching available versions to upgrade to
[upgrade/versions] Cluster version: 1.35.10
[upgrade/versions] kubeadm version: v1.35.10
I1121 20:12:18.436807   75867 version.go:260] remote version is much newer: v1.37.2;
falling back to: stable-1.35
[upgrade/versions] Target version: v1.35.10
[upgrade/versions] Latest version in the v1.35 series: v1.35.10

kubeadm v1.35 sees v1.37.2 but only plans within v1.35, and there is nothing to do there. You only get the plan for v1.36 with kubeadm v1.36 (Day 6). The command is still useful today: it runs the cluster health checks. If they fail, you stop.

Save your progress? Sign up for free

Drill 3: etcdctl and etcdutl

The tools in the version of the running etcd (Day 1: 3.6.6):

ARCH=$(dpkg --print-architecture)
curl -fsSLo /tmp/etcd.tgz \
  https://github.com/etcd-io/etcd/releases/download/v3.6.6/etcd-v3.6.6-linux-$ARCH.tar.gz
tar -xzf /tmp/etcd.tgz -C /tmp
sudo install /tmp/etcd-v3.6.6-linux-$ARCH/etcdctl \
  /tmp/etcd-v3.6.6-linux-$ARCH/etcdutl /usr/local/bin/
etcdctl version | head -1

Expected:

etcdctl version: 3.6.6

The credentials are always the same three files. Check all three members:

sudo etcdctl --endpoints=https://172.16.0.126:2379,https://172.16.0.228:2379,\
https://172.16.0.83:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt \
  --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key \
  endpoint health -w table

Expected:

+---------------------------+--------+-------------+-------+
|         ENDPOINT          | HEALTH |    TOOK     | ERROR |
+---------------------------+--------+-------------+-------+
| https://172.16.0.126:2379 |   true | 40.345311ms |       |
|  https://172.16.0.83:2379 |   true | 65.003258ms |       |
| https://172.16.0.228:2379 |   true | 91.115622ms |       |
+---------------------------+--------+-------------+-------+

Who is the leader? endpoint status has many columns; cut picks the important ones:

sudo etcdctl --endpoints=https://172.16.0.126:2379,https://172.16.0.228:2379,\
https://172.16.0.83:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt \
  --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key \
  endpoint status -w table | cut -d'|' -f2,4,6,10 | grep -v '^+'

Expected:

         ENDPOINT          | VERSION | DB SIZE | IS LEADER
 https://172.16.0.126:2379 |   3.6.6 |  9.2 MB |      true
 https://172.16.0.228:2379 |   3.6.6 |  9.2 MB |     false
  https://172.16.0.83:2379 |   3.6.6 |  9.3 MB |     false

Save your progress? Sign up for free

Drill 4: The etcd snapshot

Warning: An etcd snapshot contains all Secrets of the cluster in plain text, unless you have set up encryption at rest. Treat the file like a root password.

sudo mkdir -p /var/backups/k8s
sudo etcdctl --endpoints=https://127.0.0.1:2379 \
  --cacert=/etc/kubernetes/pki/etcd/ca.crt --cert=/etc/kubernetes/pki/etcd/server.crt \
  --key=/etc/kubernetes/pki/etcd/server.key \
  snapshot save /var/backups/k8s/etcd-v1.35.10.db

Expected (abridged):

{"level":"info",…,"msg":"fetched snapshot","endpoint":"https://127.0.0.1:2379",
"size":"9.2 MB","took":"452.189659ms","etcd-version":"3.6.0"}
Snapshot saved at /var/backups/k8s/etcd-v1.35.10.db
Server version 3.6.0

Older guides put ETCDCTL_API=3 in front of it. Since etcd 3.6, this is the only API left; the variable only produces a warning (unrecognized environment variable). Leave it out. Check the snapshot:

sudo etcdutl snapshot status /var/backups/k8s/etcd-v1.35.10.db -w table

Expected:

+----------+----------+------------+------------+---------+
|   HASH   | REVISION | TOTAL KEYS | TOTAL SIZE | VERSION |
+----------+----------+------------+------------+---------+
| 7125b235 |    14594 |        820 |     9.2 MB |   3.6.0 |
+----------+----------+------------+------------+---------+

The revision is the state a restore jumps back to. Everything that happens after it is gone after a restore: new Deployments, changed Secrets, but also Leases and endpoints. On Day 9 you experience what that means in practice.

Save your progress? Sign up for free

Drill 5: Back up /etc/kubernetes and get it off the node

etcd alone is not enough. /etc/kubernetes holds the control plane certificates, the kubeconfigs and the static Pod manifests. Without the CA from pki/, old data does not match new certificates.

sudo tar -czf /var/backups/k8s/etc-kubernetes-v1.35.10.tgz -C / etc/kubernetes
sudo ls -la /var/backups/k8s/

Expected:

total 9052
drwxr-xr-x 2 root root    4096 Nov 21 20:12 .
drwxr-xr-x 3 root root    4096 Nov 21 20:12 ..
-rw-r--r-- 1 root root   36235 Nov 21 20:12 etc-kubernetes-v1.35.10.tgz
-rw------- 1 root root 9220128 Nov 21 20:12 etcd-v1.35.10.db

A backup on the node you are about to change is not a backup. Copy both somewhere else. In the lab to cp2, in production to storage outside the cluster:

sudo cp /var/backups/k8s/etcd-v1.35.10.db /var/backups/k8s/etc-kubernetes-v1.35.10.tgz /tmp/
sudo chown $USER /tmp/etcd-v1.35.10.db /tmp/etc-kubernetes-v1.35.10.tgz
scp /tmp/etcd-v1.35.10.db /tmp/etc-kubernetes-v1.35.10.tgz [email protected]:/tmp/
ssh [email protected] "sudo mkdir -p /var/backups/k8s && \
  sudo mv /tmp/etcd-v1.35.10.db /tmp/etc-kubernetes-v1.35.10.tgz /var/backups/k8s/ && \
  sudo ls -la /var/backups/k8s/"
rm -f /tmp/etcd-v1.35.10.db /tmp/etc-kubernetes-v1.35.10.tgz

Expected:

total 9052
drwxr-xr-x 2 root   root      4096 Nov 21 20:13 .
drwxr-xr-x 3 root   root      4096 Nov 21 20:13 ..
-rw-r--r-- 1 ubuntu ubuntu   36235 Nov 21 20:13 etc-kubernetes-v1.35.10.tgz
-rw------- 1 ubuntu ubuntu 9220128 Nov 21 20:13 etcd-v1.35.10.db

Save your progress? Sign up for free

Drill 6: The go/no-go before the upgrade

Five checks, each a single command. Only when all of them pass does the upgrade start tomorrow.

kubectl get nodes
kubectl get pdb -A
pluto detect-all-in-cluster --target-versions k8s=v1.36.0
sudo kubeadm upgrade plan 2>&1 | grep -i 'health\|error'
sudo etcdutl snapshot status /var/backups/k8s/etcd-v1.35.10.db -w table

Expected:

  • all three nodes Ready
  • no PDB with ALLOWED DISRUPTIONS 0
  • There were no resources found with known deprecated apiVersions.
  • only [upgrade] Running cluster health checks, no error line
  • the snapshot table from Drill 4

A sixth check is still missing here; it is added on Day 8: does every add-on support the target version?

Save your progress? Sign up for free

Exercise: Speed Drills

  1. Count the keys in etcd that belong to Secrets. Target time: 2 min
  2. Find all lines about kubeadm in the v1.36.0 section of the changelog. Target time: 2 min
  3. Show when the last snapshot was created and how big it is, without etcdutl. Target time: 1 min

Solution

sudo etcdctl --endpoints=https://127.0.0.1:2379 \
  --cacert=/etc/kubernetes/pki/etcd/ca.crt --cert=/etc/kubernetes/pki/etcd/server.crt \
  --key=/etc/kubernetes/pki/etcd/server.key \
  get /registry/secrets --prefix --keys-only | grep -c .
awk '/^# v1.36.0$/{f=1} /^# v1.36.0-rc/{f=0} f' CHANGELOG-1.36.md | grep -i kubeadm \
  | cut -c1-88
sudo ls -la --time-style=long-iso /var/backups/k8s/

Save your progress? Sign up for free

Checkpoint

sudo etcdutl snapshot status /var/backups/k8s/etcd-v1.35.10.db -w table

Expected: the table with REVISION, TOTAL KEYS and VERSION 3.6.0.

ssh [email protected] sudo ls /var/backups/k8s/

Expected:

etc-kubernetes-v1.35.10.tgz
etcd-v1.35.10.db

Challenge

A snapshot you have never restored is a hope. Check whether it can be restored without touching the running cluster.

Hint: etcdutl snapshot restore writes to a directory of your choice.

Solution

sudo etcdutl snapshot restore /var/backups/k8s/etcd-v1.35.10.db --data-dir /tmp/etcd-probe
sudo du -sh /tmp/etcd-probe
sudo ls /tmp/etcd-probe/member
sudo rm -rf /tmp/etcd-probe

Expected (abridged):

… restored snapshot {"path": "/var/backups/k8s/etcd-v1.35.10.db", "wal-dir":
"/tmp/etcd-probe/member/wal", "data-dir": "/tmp/etcd-probe", …}
70M /tmp/etcd-probe
snap
wal

The directory is a complete etcd data directory. On Day 9, in an emergency, you put exactly such a directory in place of /var/lib/etcd.

Save your progress? Sign up for free

Cleanup

Nothing. The backups stay; they are your way back for Days 6 to 9.

Interview Note

  • What belongs in a complete control plane backup? An etcd snapshot plus /etc/kubernetes (above all pki/), stored outside the cluster.
  • How do you know what an upgrade changes? From the “Urgent Upgrade Notes” in the changelog, entries marked “ACTION REQUIRED”.
  • Why is kubeadm upgrade plan with the old kubeadm not enough? It only plans up to its own version. For the next minor version, kubeadm has to be upgraded first.

Enterprise Note

  • Snapshots run automatically and regularly, not only before upgrades, encrypted and with retention periods. Velero or the backup function of the distribution often takes care of this.
  • Change management usually requires a written way back with a time estimate: how long does a restore take, and who decides on it?
  • For upgrades there is often a staging cluster with the same version, on which the plan runs first.

Contents

More