Before upgrading, ensure:
- Backup etcd: Take a snapshot of etcd (for clusters using kubeadm).
- Check current version:
kubectl version --short
- Review Kubernetes release notes: Identify deprecations & breaking changes.
- Check compatibility:
Ensure worker nodes and control plane are compatible with the target version.
kubectl get nodes -o wide
- Drain workload from nodes:
kubectl drain <node-name> --ignore-daemonsets --delete-emptydir-data
Upgrade kubeadm on the control plane node:
apt update && apt install -y kubeadm=<target-version>Check the available versions:
apt-cache madison kubeadmRun a dry-run to check issues:
kubeadm upgrade planApply the upgrade on the control plane:
kubeadm upgrade apply v<target-version>Update binaries:
apt install -y kubelet=<target-version> kubectl=<target-version>
systemctl restart kubeletapt update && apt install -y kubeadm=<target-version>Check upgrade plan:
kubeadm upgrade nodekubectl drain <worker-node> --ignore-daemonsets --delete-emptydir-dataapt install -y kubelet=<target-version>
systemctl restart kubelet
kubectl uncordon <worker-node>- Verify all nodes are in
Readystate:kubectl get nodes
- Check cluster functionality:
kubectl get pods -A
- Validate API Server:
kubectl cluster-info
- Restart CNI (if required, for networking issues).
- Use Immutable Container Images: Ensure workloads run fixed versions of images.
- Audit Logs: Monitor logs for issues post-upgrade.
- Enable RBAC Policies: Ensure security policies remain intact.
- Monitor Network Policies: Verify pod-to-pod and external communication after the upgrade.
- Verify Pod Security Standards (PSS): Ensure security contexts are still enforced.
If the upgrade fails:
- Check etcd backup and restore if needed:
ETCDCTL_API=3 etcdctl snapshot restore <snapshot-file>
- Revert Kubelet and Kubectl:
apt install -y kubelet=<previous-version> kubectl=<previous-version> systemctl restart kubelet
- Rejoin Worker Nodes:
kubeadm reset kubeadm join <control-plane-ip>:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash>
| Task | Command |
|---|---|
| Backup etcd | ETCDCTL_API=3 etcdctl snapshot save snapshot.db |
| Check upgrade plan | kubeadm upgrade plan |
| Upgrade Control Plane | kubeadm upgrade apply vX.Y.Z |
| Upgrade Worker Node | kubeadm upgrade node |
| Restart Kubelet | systemctl restart kubelet |
| Drain Node | kubectl drain <node> |
| Uncordon Node | kubectl uncordon <node> |
| Check Cluster Status | kubectl get nodes |