使用nodeSelector的Kubernetes失败调度

问题描述

我使用Rancher设置了一个本地Kubernetes集群,其中包含3个Centos节点和1个Windows节点。 我想设置一个永远不会在Windows节点上运行的Deployment,所以我在Deployment spec.template.spec.nodeselector中设置:kubernetes.io/os:linux

它似乎可以运行,但是部署陷入“挂起”状态,并出现以下错误

警告失败调度认调度程序0/4节点为 可用:1个节点与节点选择器不匹配,3个节点有异味 {cattle.io/os:linux},该Pod无法容忍。

有什么见解吗?

解决方法

调度程序无法在Linux节点上调度pod,因为这些节点有污点。因此,您需要在部署的Pod规范中添加tolerations

  tolerations:
  - key: "cattle.io/os"
    operator: "Equal"
    value: "linux"
    effect: "NoSchedule"

还向Windows节点添加特定的污点,以便仅将具有特定容差的特定容器仅安排到Windows节点上

kubectl taint nodes windowsnode cattle.io/os=windows:NoSchedule