Search code examples
kubernetesschedulingkube-scheduler

Pod affinity to nodes with the same label


I am in situation where number of nodes is reasonably large. Nodes are consumable and can be added and removed (if idle) at any time. All nodes would have labels

label.category=A or label.category=B

I want to schedule my pods onto nodes with the same category. I really do not wish to hardcode which one. All I want is that a group of pods would end up in the same category nodes.


Solution

  • you may wanted to use Pod Topology Spread Constraints, as example below

    apiVersion: v1
    kind: Pod
    metadata:
    name: mypod
    spec:
     topologySpreadConstraints:
        - maxSkew: <integer>
          topologyKey: <string>
          whenUnsatisfiable: <string>
          labelSelector: <object>