user4202236
user4202236

Reputation: 210

Assign affinity for distributing the kubernetes pods across all nodes?

What rules should be used to assign affinity to Kubernetes pods for distributing the pods across all Availability Zones? I have a region with 3 Availability Zones and Nodes in each of these. I want to make sure that each of the 3 pods are spread across all the 3 Availability Zones.

Upvotes: 2

Views: 512

Answers (1)

Jonas
Jonas

Reputation: 129075

You should be able to use the label topology.kubernetes.io/zone (for e.g. topologyKey) and add anti-affinity rules.

This is part of the anti-affinity example:

    podAntiAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 100
        podAffinityTerm:
          labelSelector:
            matchExpressions:
            - key: security
              operator: In
              values:
              - S2
          topologyKey: failure-domain.beta.kubernetes.io/zone

the result of the example is documented as

The pod anti-affinity rule says that the pod cannot be scheduled onto a node if that node is in the same zone as a pod with label having key "security" and value "S2".

Instead of the label security in the example, you can use e.g. app-name: <your-app-name> as label and use that in your matchExpression.

Upvotes: 2

Related Questions