一、专用节点

如果想将某些节点专门分配给特定的一组用户使用,可以给这些节点添加一个Taint

$ kubectl taint nodes nodename dedicated=groupName:NoSchedule

然后给这组用户的Pod添加一个相对应的Toleration,那么拥有上述Toleration的Pod就能够被分配到上述专用节点,同时也能够被分配到集群中的其他节点。

...
...
...
tolerations:
- key: "dedicated"
  operator: "Equal"
  value: "groupName"
  effect: "NoSchedule"

如果希望这些Pod只能分配到上述专用节点中,那么还需要给这些专用节点另外添加一个和上述Taint类似的Label(例如dedicated=groupName)

[root@k8s-master01 ~]# kubectl label node k8s-node01 dedicated=groupName

然后给Pod增加节点亲和性要求或者使用NodeSelector,就能将Pod只分配到添加了dedicated=groupName标签的节点上。

...
...
...
nodeSelector:
    dedicated: "groupName"
...
...
...

二、特殊硬件的节点

在部分节点上配备了特殊硬件(比如GPU)的集群中,我们只允许特定的Pod才能部署在这些节点上。这时可以使用Taint进行控制,添加Taint,如kubectl taint nodes nodename special=true:NoSchedule或者kubectl taint nodes nodename special=true:PreferNoSchedule

$ kubectl taint nodes nodename special=true:NoSchedule

然后给需要部署在这些节点上的Pod添加相匹配的Toleration即可。

...
...
...
tolerations:
- key: "special"
  operator: "Equal"
  value: "true"
  effect: "NoSchedule"

三、基于Taint的驱逐

Taint的effect值NoExecute,它会影响已经在节点上运行的Pod。如果Pod不能忍受effect值为NoExecute的Taint,那么Pod将会被马上驱逐。如果能够忍受effect值为NoExecute的Taint,但是在Toleration定义中没有指定tolerationSeconds,则Pod还会一直在这个节点上运行。

针对NoExecute,我们可以自定义驱逐时间(默认300s),下面配置示例是3600秒:

tolerations:
- key: "key1"
  operator: "Equal"
  value: "value1"
  effect: "NoExecute"
  tolerationSeconds: 3600