LinuxCommandLibrary

kubectl-drain

evicts pods from a node for maintenance

TLDR

Drain node

$ kubectl drain [node-name]
copy
Drain ignoring DaemonSets
$ kubectl drain [node-name] --ignore-daemonsets
copy
Drain with force
$ kubectl drain [node-name] --force
copy
Drain and delete local data
$ kubectl drain [node-name] --delete-emptydir-data
copy
Drain with timeout
$ kubectl drain [node-name] --timeout=[5m]
copy
Dry run drain
$ kubectl drain [node-name] --dry-run=client
copy

SYNOPSIS

kubectl drain [options] node

DESCRIPTION

kubectl drain safely evicts all pods from a node in preparation for maintenance operations such as kernel upgrades, hardware repairs, or Kubernetes version updates. It first cordons the node to prevent new pods from being scheduled, then uses the Eviction API to gracefully terminate each pod, allowing their controllers to reschedule them onto other available nodes.
The command respects PodDisruptionBudgets (PDBs), which means it will block if evicting a pod would violate the application's availability requirements. DaemonSet-managed pods are not evicted by default since they are expected to run on every node; use `--ignore-daemonsets` to proceed without error. Pods with local storage (emptyDir volumes) also require explicit acknowledgment via `--delete-emptydir-data`, as their data will be lost.
After maintenance is complete, the node must be uncordoned with `kubectl uncordon` to resume accepting new pod scheduling. A `--timeout` flag allows setting a maximum wait time for the drain to complete before it is aborted.

PARAMETERS

NODE

Node name to drain.
--ignore-daemonsets
Ignore DaemonSet pods.
--force
Continue despite errors.
--delete-emptydir-data
Delete emptyDir data.
--timeout DURATION
Drain timeout.
--grace-period N
Pod termination grace.
--help
Display help information.

CAVEATS

Subcommand of kubectl. Respects PDBs. Use uncordon to restore.

HISTORY

kubectl drain provides safe node evacuation for Kubernetes cluster maintenance operations.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community