<p>In the documentation about affinity and anti-affinity rules for kubernetes there is a pratical use case arround a <a href="https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#more-practical-use-cases" rel="nofollow noreferrer">web application and a local redis cache</a>. </p>

<ol>
<li>The redis deployment has PodAntiAffinity configured to ensure the scheduler does not co-locate replicas on a single node.</li>
<li>The webapplication deployment has a pod affinity to ensure the app is scheduled with the pod that has label store (Redis).</li>
</ol>

<p>To connect to the redis from the webapp we would have to define a service.</p>

<p>Question: How are we sure that the webapp will always use the redis that is co-located on the same node and not another one? If I read the <a href="https://kubernetes.io/docs/concepts/services-networking/service/#version-compatibility" rel="nofollow noreferrer">version compatibility</a> from Kubernetes v1.2 the <strong>iptables mode</strong> for kube-proxy became the <strong>default</strong>.</p>

<p>Reading the docs about <a href="https://kubernetes.io/docs/concepts/services-networking/service/#proxy-mode-iptables" rel="nofollow noreferrer">iptable mode for kube-proxy</a> it says <strong>by default</strong>, kube-proxy in iptables mode <strong>chooses a backend at random</strong>.</p>

<p><s>
So my answer to the question would be:
<strong>No we can't be sure</strong>. If you want to be sure then put the redis and webapp in one pod? </s></p>

Geoffrey Samper
<p>This can be configured in the (redis) Service, but in general it is not recommended:</p>

<blockquote>
  <p>Setting <code>spec.externalTrafficPolicy</code> to the value <code>Local</code> will only proxy requests to local endpoints, never forwarding traffic to other nodes</p>
</blockquote>

<p>This is a complex topic, read more here:</p>

<ul>
<li><a href="https://kubernetes.io/docs/tutorials/services/source-ip/" rel="nofollow noreferrer">https://kubernetes.io/docs/tutorials/services/source-ip/</a></li>
<li><a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/service/</a></li>
</ul>
