<p>I have a ClusterIP Service which is used to distribute load to 2 PODs internally.
The load is not distributed evenly across the PODs.</p>

<p>How to make the load distributed evenly ?</p>

Chandu
<p>Kubernetes uses iptables to distribute the load between pods (<a href="https://kubernetes.io/docs/concepts/services-networking/service/#proxy-mode-iptables" rel="nofollow noreferrer">iptables proxy mode</a> by default).</p>

<p>If you have 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>If there would be 3 pods, probability will change to 1/3 (33%), for 4 pods 1/4 and so on.</p>

<p>To check it you can run <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 "default/nginx:" -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>If you want to make sure load is distributed evenly using round-robin algorithm you can use <a href="https://kubernetes.io/blog/2018/07/09/ipvs-based-in-cluster-load-balancing-deep-dive/" rel="nofollow noreferrer">IPVS</a> which by default uses rr (round-robin). It works as load balancer in front of a cluster and directs requests for TCP- and UDP-based services to the real servers, and make services of the real servers appear as virtual services on a single IP address. It is <a href="https://github.com/kubernetes/kubernetes/blob/master/pkg/proxy/ipvs/README.md#run-kube-proxy-in-ipvs-mode" rel="nofollow noreferrer">supported</a> on cluster created by local-up, kubeadm and GCE.</p>
