Drain and Shut Down a Bare-Metal Kubernetes Node

In progress Kubernetes Linux

Goal

Power off a node for maintenance without corrupting its disk or disrupting workloads, then return it to service.

Prerequisites

  • kubectl access to the cluster and SSH access to the node.
  • Enough capacity on the other nodes for the evicted pods.

Steps

  1. Evict the workloads (Kubernetes layer). This cordons the node and moves its pods elsewhere:
    kubectl drain <node> --ignore-daemonsets --delete-emptydir-data
    
  2. Stop the Kubernetes services on the node, before the OS shutdown:
    sudo systemctl stop kubelet containerd
    
    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.
  3. Halt the machine (OS layer):
    sudo shutdown -h now
    
  4. 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> shows SchedulingDisabled and no app pods remain on it.
  • After return: the node is Ready without SchedulingDisabled.

Troubleshooting

References