Sub topic 13
Draining and upgrading worker nodes
This chapter assumes you have already upgraded the control plane, understand the version skew policy, and know what a PodDisruptionBudget (PDB) is. Commands use a kubeadm-managed cluster.
Why nodes go one at a time
A kubelet may be up to three minor versions older than the API server, but never newer. So the control plane always goes first. Workers can follow later, though you should not leave them behind for long.
Upgrading a kubelet restarts the node's container management. To keep workloads available, you move Pods off the node first, upgrade it, and then let it take Pods again. Doing this one node at a time, or in small batches, keeps capacity high.
Step 1: Drain the node
Draining first cordons the node, which marks it unschedulable. Then it evicts the Pods. Run it from a machine with kubectl access:
kubectl drain <node-name> --ignore-daemonsets --delete-emptydir-data--ignore-daemonsetsis needed because DaemonSet Pods cannot be moved. They stay on the node.--delete-emptydir-dataallows eviction of Pods that useemptyDirvolumes. Their data is lost, so check that this is acceptable.
Eviction respects PDBs. If evicting a Pod would break a budget, the drain waits and retries. This PDB keeps at least two web Pods running:
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: web-pdb
spec:
minAvailable: 2
selector:
matchLabels:
app: webStep 2: Upgrade the node
On the node itself, install the new kubeadm package, then run:
sudo kubeadm upgrade nodeOn a worker, this updates the local kubelet configuration. It does not touch the control plane. Next, install the new kubelet and kubectl packages using your distribution's package manager, then restart the kubelet:
sudo systemctl daemon-reload
sudo systemctl restart kubeletStep 3: Uncordon and check
kubectl uncordon <node-name>
kubectl get nodesThe node should show Ready and the new version in the VERSION column. Only then move on to the next node. Uncordoning does not move Pods back. New Pods are scheduled onto the node as they are created.
Common errors
| Symptom | Likely cause |
|---|---|
| Drain hangs | A PDB cannot be satisfied, or a Pod is stuck terminating |
| Drain refuses to start | Unmanaged Pods with no controller, which need `--force` and will not be recreated |
| Node stays `NotReady` | The kubelet failed to start. Check `journalctl -u kubelet` |
| Pods stay `Pending` | Other nodes have no spare capacity while this one is drained |
Exercise
A drain of a worker node has run for ten minutes without finishing. One PDB has minAvailable: 3, and the matching Deployment has 3 replicas. Why does it hang, and what is a safe fix?
Show answer
Evicting any of the 3 Pods would leave only 2 available, which violates the budget, so every eviction is refused and retried. A safe fix is to scale the Deployment to 4 or more replicas, or to lower minAvailable to 2. Both let one Pod be evicted at a time. Bypassing the PDB with --disable-eviction risks an outage.