<p>I have 12 K8 deployments that should be distributed somewhat evenly across 3 K8 nodes based on resource utilization (like the uptime command). I expected Kubernetes to automatically choose the node that is utilizing the least amount of resources at the time of pod creation, which I would think should result in a somewhat even distribution, but to my surprise Kubernetes is creating the majority of the Pods on the same single node that is barely handling the load, while the other nodes are not being utilized almost at all.</p>
<p>I heard about using topologySpreadConstraints like so</p>
<pre><code>topologySpreadConstraints:
              - maxSkew: 1
                topologyKey: kubernetes.io/hostname
                whenUnsatisfiable: ScheduleAnyway
                labelSelector:
                    matchLabels:
                      type: wordpress-3 
</code></pre>
<p>But I cant get it to work properly, what is the correct way to achieve the even distribution behavior of deployments that I am looking for? thanks!</p>

Evyatar Saias
<p>Are you using bitnami's wordpress chart?</p>
<p>If so you can update the <code>values.yaml</code> you pass into the chart and set anti-affinity like this:</p>
<pre class="lang-yaml prettyprint-override"><code>
# Affinity
affinity:
  podAntiAffinity:
    requiredDuringSchedulingIgnoredDuringExecution:
    - topologyKey: kubernetes.io/hostname
      labelSelector:
        matchLabels:
          app.kubernetes.io/instance: {name of your Wordpress release}

</code></pre>
<p>This will force kubernetes to only allow one Wordpress pod on one host (i.e. node). I use this setup on my own Wordpress installations and it means if one node goes down, it doesn't take out the site as the other replicas will still be running and on separate nodes</p>
