kubectl drain - Drain node in preparation for maintenance
kubectl drain NODE [--ignore-daemonsets] [--delete-emptydir-data] [--force] [--grace-period=N] [--timeout=D] [--disable-eviction]
Options you will use
--ignore-daemonsets- DaemonSet pods would be recreated on the node anyway: skip them
--delete-emptydir-data- evict pods with emptyDir volumes (their data is lost)
--force- also delete pods with no controller (they are gone for good)
--timeout=D- give up after D (default: wait forever)
--disable-eviction- DELETE instead of evict: bypasses PodDisruptionBudgets. Last resort.
Examples
$ kubectl drain worker-1 --ignore-daemonsets --delete-emptydir-datathe standard maintenance drain
$ kubectl uncordon worker-1allow scheduling again afterwards
Gotchas
- drain = cordon + evict every pod through the Eviction API. The Eviction API honours PodDisruptionBudgets: "Cannot evict pod as it would violate the pod's disruption budget." and drain retries every 5s - forever, unless --timeout is set.
Taught in
Try kubectl drain in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.