<p>I have been wondering how an internal Kubernetes service distributes the load of requests made from within the cluster to all PODs associated with the service. For example, given the following simple service from <a href="https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service" rel="nofollow noreferrer">K8s docs</a>.</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app.kubernetes.io/name: MyApp
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376
</code></pre>
<p>I understand that the default service type is <a href="https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types" rel="nofollow noreferrer">ClusterIP</a> when the type property is not specified. But I couldn't find any docs clearly stating how all requests for this kind of service are distributed across the selected PODs.</p>
<p>The far I've got was to this <a href="https://groups.google.com/g/kubernetes-users/c/lvfyKzUf-Vg" rel="nofollow noreferrer">post</a> where there's a comment from <em>Tim Hockin</em> stating the following</p>
<blockquote>
<p>The load is random, but the distribution should be approximately equal for non-trivial loads. E.g. when we run tests for 1000 requests you can see it is close to equal.</p>
</blockquote>
<p>Is this the policy followed by <code>CluterIP</code> services? Can someone give more clarity on this topic?</p>

João Pedro Schmitt
<p>The request load distribuition depends on what proxy mode is configured in your cluster on the kube-proxy. Often the chosen configuration is iptables. And according to the <a href="https://kubernetes.io/docs/reference/networking/virtual-ips/#proxy-mode-iptables" rel="nofollow noreferrer">documentation</a> on it:</p>
<blockquote>
<p>In this mode, kube-proxy watches the Kubernetes control plane for the addition and removal of Service and EndpointSlice objects. For each Service, it installs iptables rules, which capture traffic to the Service's clusterIP and port, and redirect that traffic to one of the Service's backend sets. For each endpoint, it installs iptables rules which select a backend Pod.
By default, kube-proxy in iptables mode chooses a backend at random.</p>
</blockquote>
<p>Usually this configuration is fine as probability will spread your requests somewhat evenly across pods. But if you need more more control over that you can change that configuration to IPVS mode where you can use round robin, least connections, among other options. More information on it can be seen <a href="https://kubernetes.io/docs/reference/networking/virtual-ips/#proxy-mode-iptables" rel="nofollow noreferrer">here</a>.</p>
<p>I hope this helps.</p>
