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
| Argument | Description |
|---|---|
<index> | Row number from the current listing, or @name for a mark; kx state or kx mark shows them |
Options
| Option | Description |
|---|---|
--delete-emptydir-data | Continue even though pods use emptyDir volumes, whose data is lost |
--force | Evict pods no controller manages, which will not come back |
--grace-period int | Seconds to give each pod to terminate; -1 uses the pod’s own |
--ignore-daemonsets | Continue even though DaemonSet-managed pods cannot be evicted |
--timeout duration | Give up waiting after this long |
-y, --yes | Skip the confirmation prompt |
Passthrough options
| Option | Description |
|---|---|
--chunk-size int64 | Return large lists in chunks rather than all at once. Pass 0 to disable. |
--disable-eviction | Force 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 string | Label selector to filter pods on the node |
-l, --selector string | Selector (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 int | If 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
| Option | Description |
|---|---|
--no-color | Disable styled output |
-h, --help | Show this message and exit |
Examples
kx drain 1
kx drain 1 --ignore-daemonsets
kx drain 1 -y --ignore-daemonsets --delete-emptydir-data