liveBook · Manning

Node drain

As explained in Acing the Certified Kubernetes Administrator Exam, Second Edition

Node draining is the process of evicting workloads from a node so it can be taken out of service or maintained.

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

How Acing the Certified Kubernetes Administrator Exam, Second Edition covers it

How deep it goes
Explains cordon, taint preparation, drain, verification, and uncordon commands, but does not detail eviction internals.
Examples
Uses a two-node kind cluster, nginx Deployments, command output, and unmanaged and DaemonSet-managed pods.
What it assumes
Assumes familiarity with taints, Deployments, ReplicaSets, DaemonSets, pod scheduling, and basic kubectl commands.
What you can do after
Operate/configure node availability with kubectl drain, verify pod relocation, and restore scheduling with kubectl uncordon.
How it connects
Connects node drain with cordon, uncordon, taints, the scheduler, DaemonSets, ReplicaSets, and Deployments.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Acing the Certified Kubernetes Administrator Exam, Second Edition. The section links point to the parts of the book it draws on.