9

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Prakash
  • 2,532
  • 6
  • 17
  • 21

4 Answers4

11

The better way is in using something like this:

  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: kubernetes.io/hostname
            operator: In
            values:
            - node1
            - node2
Alexey Yakunin
  • 364
  • 3
  • 3
6

The nodeSelector on a PodSpec is just a map[string]string (instead of the more featureful NodeSelector type that is used in the NodeAffinity object).That means that the key "app" can only have one value, and it ends up being overwritten as "node2".

You can accomplish the scheduling between node1 and node2 by applying a common label (e.g. scheduling-group: foo), and then have your replicationController use that label as the nodeSelector.

CJ Cullen
  • 5,452
  • 1
  • 26
  • 34
1

Yes, you can.

If you want the pods to be scheduled to either node1 or node2, you may label both nodes with the same label(s) (for example, app=node), and then add app=node as your nodeSelector. You can add as many labels as you want, but like CJ mentioned, nodeSelector is a map with key and value pairs so it can't have the same key with different values.

The pods can be scheduled on any of the nodes that satisfy that nodeSelector.

For more information, read Assigning Pods to Nodes. Note that there's a new feature called nodeAffinity that you might also want to try.

janetkuo
  • 2,635
  • 14
  • 17
  • the question is clearly asking about a nodes w/ different label values, this answer is just valid if the user have admin permissions on this cluster and can change/update the node labels – Gongora Sep 17 '20 at 20:08
1

No cannot use the same key name for key/value pairs in YAML dictionaries. Use different keys. To schedule a pod to nodes labled with node:super or nodetype:duper:

spec:
  nodeSelector: { node: "super", nodetype: "duper" }

In YAML

martin:
  name: Martin D'vloper
  job: Developer
  skill: Elite

is the same with:

martin: {name: Martin D'vloper, job: Developer, skill: Elite}

If it can be one line, it is easier to manipulate.

mon
  • 18,789
  • 22
  • 112
  • 205
  • 1
    Is the pod scheduled either 'node: "Super"' or 'nodetype: "dupler' ? Or The pod will be scheduled on the node where has both 'node:"super"', _AND_ 'nodetype:"duper"'? – Sungguk Lim Aug 28 '20 at 03:15