<p>In my kubernetes cluster, there is a lot of inter-service communication. I have also enabled horizontal pod autoscaler and we use <strong>service</strong> resource for all these services. </p>

<p>I need to understand how does the <strong>service</strong> resource loadbalance the request across the pods. </p>

<p>I did read about <strong>SessionAffinity</strong> but it only supports ClientIP, if you are not using an Ingress resource.</p>

<p>Want to know if the service can loadbalance based on the load (in terms of cpu, memory, etc.) on a particular pod. In short, does <strong>sessionAffinity</strong> config support anything other than ClientIP. I dont want to bring in an <strong>Ingress</strong> resource, as these are not external facing requests, these are inter-service communication.</p>

<p>Thanks in advance.</p>

Amit
<blockquote>
  <p>In short, does sessionAffinity config support anything other than ClientIP</p>
</blockquote>

<p>No, it does not. See the <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/#sessionaffinityconfig-v1-core" rel="nofollow noreferrer">model definition here</a> for <code>v1.SessionAffinityConfig</code>: Nor will it; I already feel that sessionAffinity is out of a Service's scope, I'm surprised it exists at all.</p>

<p>You're going to want to use some kind of layer in front of your service if you want to have more control of your connections. There are plenty of Service Meshes that might solve your problem (see <a href="https://istio.io" rel="nofollow noreferrer">isito</a> or <a href="https://linkerd.io/" rel="nofollow noreferrer">Linkerd</a> )</p>

<p>You could also roll your own solution with nginx and send your requests for that service to the nginx pod.</p>
