<p>I'm running a Kubernetes cluster of 3 nodes with GKE. I ask Kubernetes for 3 replicas of <code>backend</code> pods. The 3 pods are not well dispatched among the nodes to provide a high-availability service, they are usually all on 2 nodes.
I would like Kubernetes to dispatch the pods as much as possible to have a pod on each node, but not fail the deployment/scale-up if they are more <code>backend</code> pods than nodes.</p>

<p>Is it possible to do that with <code>preferredDuringSchedulingIgnoredDuringExecution</code>?</p>

<p>Try setting up an preferred antiAffinity rule like so:</p>

<pre><code>affinity:
    podAntiAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
        - labelSelector:
            matchExpressions:
              - key: "app"
                operator: In
                values: 
                - "my_app_name"
          topologyKey: "kubernetes.io/hostname"
</code></pre>

<p>This will try to schedule pods onto nodes which do not already have a pod of the same label running on them. After that it's a free for all (so it won't evenly spread them after making sure at least 1 is running on each node). This means that after scaling up you might end up with a node with 5 pods, and other nodes with 1 pod each.</p>
