Node draining evicts workloads from a node so it can undergo maintenance or leave service. Unlike cordoning, draining removes existing pods; controllers may recreate managed pods elsewhere. section 5.2 section 5.2.1
Use this operational sequence:
- Cordon the node with `kubectl cordon kind-worker` to disable new scheduling and verify `Ready,SchedulingDisabled`. section 5.2 section 5.2.1
- Remove blocking taints from an available destination node when necessary, such as `kubectl taint no kind-control-plane node-role.kubernetes.io/control-plane:NoSchedule-`. section 5.2
- Drain with `kubectl drain kind-worker --ignore-daemonsets`; use `--force` when unmanaged pods prevent eviction. section 5.2 section 5.2.1
- Verify placement with `kubectl get po -o wide`, then restore scheduling with `kubectl uncordon kind-worker`. section 5.2 section 5.2.1
Draining a two-node cluster
After draining `kind-worker`, a Deployment-managed nginx pod is recreated on `kind-control-plane`, while DaemonSet-managed system pods are ignored. An unmanaged pod can be deleted permanently because no controller recreates it. section 5.2 section 5.2.1
root@kind-control-plane:/# kubectl drain kind-worker --ignore-daemonsets node/kind-worker already cordoned Warning: ignoring DaemonSet-managed Pods: kube-system/kindnet-h7695, kube-system/kube-proxy-j8wbc evicting pod default/nginx-76d6c9b8c-hr9z6 pod/nginx-76d6c9b8c-hr9z6 evicted node/kind-worker drained root@kind-control-plane:/# kubectl get po -o wide NAME READY STATUS RESTARTS AGE IP NODE nginx-76d6c9b8c-4494r 1/1 Running 0 52s 10.244.0.7 kind-control-plane nginx2-b648d744f-n6xb9 1/1 Running 0 3m6s 10.244.0.6 kind-control-plane
Shows the drain command, DaemonSet warnings, pod eviction, and resulting pod placement. section 5.2
