<p>We are running our application with 3 pods on a 3 node kubernetes cluster. When we deploy out application, sometimes, pods are getting scheduled to the same kubernetes node.</p>

<p>We want our pods to scheduled in such a way that it spread our pods across nodes ( no 2 pods of the same application should be same node). Infact, as per documentation(<a href="https://kubernetes.io/docs/concepts/configuration/assign-pod-node/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/configuration/assign-pod-node/</a>), kubernetes already does a good job in this.  However, if it doesn't find resources, it schedules it to the same node. How do it make it a hard constraint ?</p>

<p>Requirement:
We want the deployment to fail or be in pending state if the pods don't obey the constraints (no 2 pods of the same application should be same node)</p>

SunilS
<p>i think this one will work </p>

<pre><code>affinity:
    podAntiAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
      - labelSelector:
          matchExpressions:
          - key: app
            operator: In
            values:
            - &lt;VALUE&gt;
        topologyKey: "kubernetes.io/hostname"
</code></pre>

<p>For more reference you can visit : <a href="https://thenewstack.io/implement-node-and-pod-affinity-anti-affinity-in-kubernetes-a-practical-example/" rel="nofollow noreferrer">https://thenewstack.io/implement-node-and-pod-affinity-anti-affinity-in-kubernetes-a-practical-example/</a></p>
