Sub topic 15
Rollback and Recovery Options
This chapter assumes you can run kubectl, know what etcd holds, and have followed the earlier chapters on backing up etcd and upgrading with kubeadm. It covers what you can undo after an upgrade and what you cannot.
Kubernetes does not support downgrades
Kubernetes does not support moving a cluster back to an earlier minor version. After the control plane upgrades, it may write objects to etcd in a newer storage format. An older API server may not be able to read those objects. Rollback therefore means restoring from a backup, not reversing the upgrade.
Treat the etcd snapshot from the planning stage as your main recovery path. The sections below ordered by cost show your options.
Choose the smallest fix first
| Situation | Option | Cost |
|---|---|---|
| A workload misbehaves on the new version | Roll back the Deployment or fix the manifest | Low |
| One node fails after its upgrade | Cordon it, drain it, and replace or repair it | Low |
| `kubeadm upgrade apply` fails partway | Fix the cause and re-run it | Medium |
| The control plane is unusable or data is damaged | Restore etcd from the snapshot | High |
Workload and node problems
If an application breaks, the cause is often a removed API or a changed default, not the cluster itself. Roll back the workload:
kubectl rollout undo deployment/web
kubectl rollout status deployment/webIf a node fails after its kubelet upgrade, do not downgrade the kubelet in place. Cordon the node, drain it, and join a fresh node at a version the control plane supports. Your PodDisruptionBudgets keep the application available during this.
Control plane failure
kubeadm upgrade apply backs up the static Pod manifests and etcd data under /etc/kubernetes/tmp before it changes them. If the upgrade fails midway, it tries to roll back its own changes. Read its output, fix the cause, and run the command again. Re-running is safe.
If the control plane cannot recover, restore the snapshot you took before starting:
sudo systemctl stop kubelet
sudo mv /var/lib/etcd /var/lib/etcd.broken
ETCDCTL_API=3 etcdutl snapshot restore /var/backups/etcd-pre-upgrade.db \
--data-dir /var/lib/etcd
sudo systemctl start kubeletBefore restoring, reinstall the previous kubeadm, kubelet, and API server versions on the control plane nodes. A restored etcd holds data in the old format, so the old binaries must read it. On a multi-node control plane, restore the same snapshot on every member and rebuild the etcd cluster configuration. Follow the etcd documentation for that case.
Rehearse the restore
An untested backup is a guess. Practice the restore on a staging cluster before the production upgrade, and write down how long it takes. That time tells you how long an outage you would face in the worst case.
Exercise
Why can you not simply reinstall the old kubeadm and kubelet packages to roll back a cluster whose control plane was upgraded successfully?
Show answer
Kubernetes does not support downgrades. The upgraded API server may have written objects to etcd in a newer format that older components cannot read. The supported recovery is to restore the pre-upgrade etcd snapshot together with the old component versions.
Exercise
A Deployment fails after the upgrade, but the nodes and control plane are healthy. Which recovery option do you try first, and why?
Show answer
Roll back the Deployment with kubectl rollout undo or fix its manifest. It is the lowest-cost option and does not affect the rest of the cluster.