Linux command
kubectl-drain 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Drain node
kubectl drain [node-name]
Drain ignoring DaemonSets
kubectl drain [node-name] --ignore-daemonsets
Drain with force
kubectl drain [node-name] --force
Drain and delete local data
kubectl drain [node-name] --delete-emptydir-data
Drain with timeout
kubectl drain [node-name] --timeout=[5m]
Dry run drain
kubectl drain [node-name] --dry-run=client
说明
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.
参数
- --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.
FAQ
What is the kubectl-drain command used for?
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.
How do I run a basic kubectl-drain example?
Run `kubectl drain [node-name]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does --ignore-daemonsets do in kubectl-drain?
Ignore DaemonSet pods.