Kubernetes worker node only for a specific type of pod

4/10/2019

I've a requirement where I want to schedule a specific type of pod on a particular node and no other types of pod should get scheduled on that node. For example,

Assuming that I've 3 worker nodes - w1, w2 and w3 I want pods of type(say POD-w2) should always get scheduled on w2 and no other type of pods should get scheduled on w2.

-- ahmed meraj
kubernetes

3 Answers

4/25/2019

To achieve this, we have to taint the node as well as affinity by labeling the node. The required pod should tolerate the taint and satisfy the affinity also. By this way pod will get scheduled ONLY on the dedicated node.

example:

kubectl taint nodes <dedicated_node_name> dedicated=myservice:NoSchedule
kubectl label node <dedicated_node_name> dedicated=myservice

then use toleration and affinity in the deployment spec

    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: dedicated
                operator: In
                values:
                - myservice

and

      tolerations:
      - effect: NoSchedule
        key: dedicated
        operator: Equal
        value: myservice
-- ahmed meraj
Source: StackOverflow

4/10/2019

Add a label type=w2 to worker 2.

Use node selector or node affinity to schedule required pods on that node.

For other pods use node anti affinity to prevent other pods getting scheduled on to the worker 2

-- P Ekambaram
Source: StackOverflow

4/10/2019

To exclusively use a node for a specific type of pod, you should taint your node as described here. Then, create a toleration in your deployment/pod definition for the node taint to ensure that only that type of pod can be scheduled on the tainted node.

-- Frank Yucheng Gu
Source: StackOverflow