title: How to spread pods evenly among all zones in kubernetes?
body: <p>I was trying to spread pods evenly in all zones, but couldn't make it work properly.</p>
  <p>In my k8s cluster, nodes are spread across 3 az's. Now suppose min node count is 1 and there are 2 nodes at the moment, first one is totally full of pods. Now when I create one deployment (replica 2) with topology spread constraints as <code>ScheduleAnyway</code> then since 2nd node has enough resources both the pods are deployed in that node. I don't want that. I tried changing condition to <code>DoNotSchedule</code>. But since I have only 3 az's, I am only able to schedule 3 pods and it's triggering new node for all 3 pods. I want to make sure that relpica's are spread in 3 all az's.</p>
  <p>Here is snippet from deployment spec. Does anyone know what should be the way out?</p>
  <pre><code>      topologySpreadConstraints:
        - maxSkew: 1
          topologyKey: topology.kubernetes.io/zone
          whenUnsatisfiable: ScheduleAnyway
          labelSelector:
            matchExpressions:
            - key: app
              operator: In
              values:
              - &quot;my-app&quot; 
  </code></pre>