can we mention more than one node label in single nodeSelector in kubernetes

Prakash picture Prakash · May 24, 2016 · Viewed 9k times · Source

i want to schedule 10 pods in two specific node(total 15 nodes in our kube cluster).

so in replication-controller file i am mentioning two values in nodeSelector like below.

nodeSelector:  
  app: node1  
  app: node2  

problem is that all the time it's taking only node2.whatever sequence i am mentioning, it's taking last node only.

note: node1 and node2 are lables of node.

Answer

Alexey Yakunin picture Alexey Yakunin · Dec 30, 2018

The better way is in using something like this:

  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: kubernetes.io/hostname
            operator: In
            values:
            - node1
            - node2