kubectl taint

管理节点污点,控制 Pod 调度到特定节点

语法

kubectl taint nodes <node-name> <key>=<value>:<effect> [flags]

参数

参数说明示例级别
NoSchedule 新 Pod 不会调度到该节点 kubectl taint nodes node1 gpu=true:NoSchedule 常用
PreferNoSchedule 尽量不调度,但不强制 kubectl taint nodes node1 load=high:PreferNoSchedule 进阶
NoExecute 驱逐已有 Pod 且不调度新 Pod kubectl taint nodes node1 maintenance=true:NoExecute 进阶
<key>- 删除污点(key:effect 后加减号) kubectl taint nodes node1 gpu=true:NoSchedule- 常用

示例

添加污点

kubectl taint nodes worker-1 dedicated=gpu:NoSchedule
只有容忍该污点的 Pod 才能调度到此节点

删除污点

kubectl taint nodes worker-1 dedicated=gpu:NoSchedule-
末尾加 - 删除指定污点

维护节点

kubectl taint nodes worker-1 maintenance=true:NoExecute
驱逐现有 Pod 并阻止新调度

标记 GPU 节点

kubectl taint nodes gpu-node-1 nvidia.com/gpu=present:NoSchedule
确保只有 GPU 工作负载调度到 GPU 节点

常见错误

taint not found 删除污点时 key、value、effect 必须完全匹配
node not found 确认节点名称,用 kubectl get nodes 查看

技巧

相关命令