<p>Inside a K8s cluster, I run a web application with 2 Pods (replica is 2), and expose a them using a <code>Service</code> with type <code>LoadBalancer</code>.
Then I do an experiment by sending 2 consecutive requests, I found that both request are handled by the same Pod.</p>
<p>Anyone can help me to explain this behavior?
And what should I do to change this behavior to round robin or something else?</p>

<p>By default, kubernetes uses <a href="https://kubernetes.io/docs/concepts/services-networking/service/#proxy-mode-iptables" rel="nofollow noreferrer"><code>iptables</code> mode</a> to route traffic between the pods. The pod that is serving request is chosen randomly.</p>
<p>For 2 pods, it is distributed evenly with 0.5 (50%) probability. Because it is not using round-robin, the backend pod is chosen randomly. It will be even in a longer time-frame.</p>
<p>It can be checked using <code>sudo iptables-save</code>.</p>
<p>Example output for 2 pods (for nginx service):</p>
<pre><code>    sudo iptables-save | grep nginx
    
    -A KUBE-NODEPORTS -p tcp -m comment --comment &quot;default/nginx:&quot; -m tcp --dport 31554 -j KUBE-SVC-4N57TFCL4MD7ZTDA    //KUBE-SVC-4N57TFCL4MD7ZTDA is a tag for nginx service
    
    sudo iptables-save | grep KUBE-SVC-4N57TFCL4MD7ZTDA
    -A KUBE-SVC-4N57TFCL4MD7ZTDA -m statistic --mode random --probability 0.50000000000 -j KUBE-SEP-SOWYYRHSSTWLCRDY
</code></pre>
<p>As mentioned by @Zambozo <a href="https://kubernetes.io/docs/concepts/services-networking/service/#proxy-mode-ipvs" rel="nofollow noreferrer">IPVS proxy mode</a> allows you to use round-robin algorithm (which is used by default) to spread the traffic equally between the pods.</p>
