<p>I could not find a documentation that specifies how Kubernetes service behaves when the affiliated deployment is scaled with multiple replicas.</p>

<p>I'm assuming there's some sort of load balancing. Is it related to the service type?</p>

<p>Also, I would want to have some affinity in the request forwarded by the service (i.e all requests with a certain suffix should always be mapped to the same pod if possible, etc). Is that achievable? Closes I've seen is <a href="https://www.envoyproxy.io/docs/envoy/latest/start/distro/ambassador" rel="noreferrer">Ambassador</a>, but that is affinity in the service level, and not pod level.</p>

Mugen
<h2>Deployment: Stateless workload</h2>
<blockquote>
<p>I could not find a documentation that specifies how Kubernetes service behaves when the affiliated deployment is scaled with multi replicas.</p>
</blockquote>
<p>Pods deployed with <code>Deployment</code> is supposed to be stateless.</p>
<h2>Ingress to Service routing</h2>
<p>When using <code>Ingress</code>, L7-proxy, the routing can be based on http request content, but this depends on what implementation of an IngressController you are using. E.g. <a href="https://kubernetes.github.io/ingress-nginx/examples/affinity/cookie/" rel="noreferrer">Ingress-nginx</a> has <em>some</em> support for <em>sticky sessions</em> and other implementations may have what you are looking for. E.g. <a href="https://istio.io/docs/reference/config/networking/destination-rule/#LoadBalancerSettings" rel="noreferrer">Istio</a> has support similar settings.</p>
<p><strong>Ambassador</strong></p>
<p><a href="https://www.getambassador.io/reference/core/load-balancer/" rel="noreferrer">Ambassador</a> that you write about does also have <em>some</em> support for <em>session affinity / sticky sessions</em>.</p>
<blockquote>
<p>Configuring sticky sessions makes Ambassador route requests to the same backend service in a given session. In other words, requests in a session are served by the same Kubernetes <strong>pod</strong></p>
</blockquote>
<h2>Pod to Service routing</h2>
<p>When a pod in your cluster does an http request to a Service within the cluster, the <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="noreferrer">kube-proxy does routing</a> in a <strong>round robin</strong> way by default.</p>
<blockquote>
<p>By default, kube-proxy in userspace mode chooses a backend via a round-robin algorithm.</p>
</blockquote>
<p>If you want session affinity on pod-to-service routing, you can set the <code>SessionAffinity: ClientIP</code> field on a <code>Service</code> object.</p>
<blockquote>
<p>If you want to make sure that connections from a particular client are passed to the same Pod each time, you can select the session affinity based on client’s IP addresses by setting service.spec.sessionAffinity to “ClientIP” (the default is “None”).</p>
</blockquote>
