Can a Pod with an affinity for one node's label, but without a toleration for that node's taint, mount to that node?

12/31/2020

Say you have Node1 with taint node1taint:NoSchedule and label node1specialkey=asdf. And Node2 with no taints.

Then you create PodA with affinity to Node1:

    apiVersion: v1
    kind: Pod
    metadata:
      labels:
        name: PodA
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: node1specialKey
                operator: Exists
      containers:
      - image: busybox
        name: PodA

Which pod should the node schedule to? Will the affinity override the taint?

Thanks!

-- Jake Stout
kubernetes

1 Answer

12/31/2020

The pod will not schedule anywhere, because it does not tolerate Node1's taint and it does not have an affinity for Node2.

Here is the missing pod taint that would, in combination with the affinity, successfully schedule PodA on Node1.

tolerations:
- key: "node1taint"
  operator: "Exists"
  effect: "NoSchedule"

A taint is more powerful than an affinity. The pod needs the toleration, too, because affinity alone is not strong enough here in Kubernetes-land.

-- Jake Stout
Source: StackOverflow