<p>I was experimenting load balancing our service by having two replicas on a cluster of two nodes.</p>

<p>Then I noticed the following:</p>

<p>Yesterday when I checked the pods, it looked like this:</p>

<pre><code>pod-jq5vr   4/4       Running   0          2m        10.4.1.5    node-vvmb
pod-qbs69   4/4       Running   0          2m        10.4.0.10   node-jskq
</code></pre>

<p>This morning:</p>

<pre><code>pod-hvjs8   4/4       Running   0          17h       10.4.1.6   node-vvmb
pod-jq5vr   4/4       Running   0          18h       10.4.1.5   node-vvmb
</code></pre>

<p>There must have been node recreation going on between yesterday and this morning, but the pod are on the same node now.</p>

<p>My questions:</p>

<ol>
<li>How can I evenly distribute the pods on both nodes?</li>
<li>Does it matter to keep them on the same node? It seems my current configuration does not guarantee they must be on the separate nodes.</li>
</ol>

<p>You can use the <a href="https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#inter-pod-affinity-and-anti-affinity-beta-feature" rel="nofollow noreferrer">pod anti-affinity</a> feature to tell the scheduler that you don't want the pods in the same service to run on the same node. </p>

<p>The kubernetes documentation also has an <a href="https://kubernetes.io/docs/tutorials/stateful-application/zookeeper/#tolerating-node-failure" rel="nofollow noreferrer">example showing how to configure zookeper with anti-affinity for high availability</a>.</p>
