Drain and Shut Down a Bare-Metal Kubernetes Node
Goal
Power off a node for maintenance without corrupting its disk or disrupting workloads, then return it to service.
Prerequisites
kubectlaccess to the cluster and SSH access to the node.- Enough capacity on the other nodes for the evicted pods.
Steps
- Evict the workloads (Kubernetes layer). This cordons the node and moves its pods elsewhere:
kubectl drain <node> --ignore-daemonsets --delete-emptydir-data - Stop the Kubernetes services on the node, before the OS shutdown:
Otherwise systemd can hang tearing down container networking while the disk is still being written, and a forced power-off then leaves a dirty ext4 journal.sudo systemctl stop kubelet containerd - Halt the machine (OS layer):
sudo shutdown -h now - After maintenance, power it on. The kubelet rejoins on its own, but the node stays cordoned. Allow scheduling again:
kubectl uncordon <node>
Verify
- Before shutdown:
kubectl get node <node>showsSchedulingDisabledand no app pods remain on it. - After return: the node is
ReadywithoutSchedulingDisabled.
Troubleshooting
drainblocked by a PodDisruptionBudget: the eviction would take an app below its minimum; scale it up first or wait.- Node comes back with a read-only filesystem: follow Recover a Read-Only Root Filesystem with fsck.
References
- Kubernetes documentation: Safely Drain a Node - drain, PodDisruptionBudgets, uncordon.
- Kubernetes MOC - hub for Kubernetes notes.