Skip to content

kx drain

Cordons a node and evicts the pods running on it, waiting for each to terminate. Streams kubectl’s own progress, which can run for minutes.

One index only, unlike kx cordon: a drain evicts running workloads and blocks until they are gone, so applying it to a range of nodes in one command is a way to take a cluster down by typo.

kubectl’s own drain flags pass through — a drain usually needs --ignore-daemonsets, and often --delete-emptydir-data.

A flag kx doesn’t know is refused; put it after -- to pass it through to kubectl.

Usage

kx drain [OPTIONS] <index> [kubectl flags]

Arguments

ArgumentDescription
<index>Row number from the current listing, or @name for a mark; kx state or kx mark shows them

Options

OptionDescription
--delete-emptydir-dataContinue even though pods use emptyDir volumes, whose data is lost
--forceEvict pods no controller manages, which will not come back
--grace-period intSeconds to give each pod to terminate; -1 uses the pod’s own
--ignore-daemonsetsContinue even though DaemonSet-managed pods cannot be evicted
--timeout durationGive up waiting after this long
-y, --yesSkip the confirmation prompt

Passthrough options

OptionDescription
--chunk-size int64Return large lists in chunks rather than all at once. Pass 0 to disable.
--disable-evictionForce drain to use delete, even if eviction is supported. This will bypass checking PodDisruptionBudgets, use with caution.
--dry-run[=string]Must be “none”, “server”, or “client”. If client strategy, only print the object that would be sent, without sending it. If server strategy, submit server-side request without persisting the resource.
--pod-selector stringLabel selector to filter pods on the node
-l, --selector stringSelector (label query) to filter on, supports ‘=’, ‘==’, ‘!=’, ‘in’, ’notin’.(e.g. -l key1=value1,key2=value2,key3 in (value3)). Matching objects must satisfy all of the specified label constraints.
--skip-wait-for-delete-timeout intIf pod DeletionTimestamp older than N seconds, skip waiting for the pod. Seconds must be greater than 0 to skip.
…kubectl’s global flags too: --context, --kubeconfig, --as and the rest; kubectl options lists them

Global options

OptionDescription
--no-colorDisable styled output
-h, --helpShow this message and exit

Examples

kx drain 1
kx drain 1 --ignore-daemonsets
kx drain 1 -y --ignore-daemonsets --delete-emptydir-data