這種方式適合讓某些 Node 只允許特定 Pod 運行,其他 Pod 不能調度到該 Node

步驟

1️⃣ 對 Node 設置 Taint

kubectl taint nodes <your-node-name> dedicated=my-service:NoSchedule

📌 NoSchedule 代表 不允許其他沒有相應 Toleration 的 Pod 調度到此 Node

2️⃣ 在 Pod 或 Deployment 加入 Toleration

只有帶有對應 Toleration 的 Pod 才可以運行在這個 Node 上

apiVersion: v1
kind: Pod
metadata:
  name: toleration-pod
spec:
  tolerations:
  - key: "dedicated"
    operator: "Equal"
    value: "my-service"
    effect: "NoSchedule"
  containers:
  - name: my-container
    image: nginx

你也可以直接把這個 Node 標記為不可調度,只有手動調度的 Pod 才能運行。

1️⃣ 標記 Node 為 NoSchedule

kubectl cordon <your-node-name>

這樣 Kubernetes 不會自動調度新的 Pod 到這個 Node

2️⃣ 如果要完全清除所有 Pod

kubectl drain <your-node-name> --ignore-daemonsets --delete-emptydir-data

這會讓所有非 DaemonSet 的 Pod 都被遷移走。