<p>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.</p>

<p>You should be able to use the label <code>topology.kubernetes.io/zone</code> (for e.g. topologyKey) and add <strong>anti-affinity</strong> rules.</p>
<p>This is part of the <a href="https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#an-example-of-a-pod-that-uses-pod-affinity" rel="nofollow noreferrer">anti-affinity example</a>:</p>
<pre><code>    podAntiAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 100
        podAffinityTerm:
          labelSelector:
            matchExpressions:
            - key: security
              operator: In
              values:
              - S2
          topologyKey: failure-domain.beta.kubernetes.io/zone
</code></pre>
<p>the result of the example is documented as</p>
<blockquote>
<p>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 &quot;security&quot; and value &quot;S2&quot;.</p>
</blockquote>
<p>Instead of the label <code>security</code> in the example, you can use e.g. <code>app-name: &lt;your-app-name&gt;</code> as label and use that in your <code>matchExpression</code>.</p>
