<p>I'd like to direct traffic from a load balancer within Kubernetes to a deployment.  However, rather than attempting to achieve a uniform load across all pods of a deployment, I'd like each connection to and maintain a connection to a specific pod.  I'll be sending GRPC requests to a stateful instance on the pod and it's critical that the client's GRPC requests are not sent to other pods.</p>

<p>My current implementation is probably needlessly complex.  Here's the pseudocode:</p>

<ol>
<li>Cluster initialized with a custom python scheduler.</li>
<li>Several pods with the stateful application are created, each with a node port service and unique node port.</li>
<li>Client talks to the python scheduler using a socket interface and is assigned a port.</li>
<li>Client talks to the pod using the assigned nodeport.</li>
<li>Client (or the scheduler) terminates the pod.</li>
</ol>

<p>I'm limited by the number of ports and am unable to direct traffic using AKS due to their node port limitations.  Additionally, though the advantage of the scheduler is the client can request pods of varying resources, but it's too much to test and maintain.</p>

<p>Is there a better solution to direct external traffic to individual stateful pods?</p>

<p>The default iptables service proxy implementation uses a very simple randomized round-robin algorithm for selecting which pod to use. If you use the IPVS implementation instead that does offer a lot more options, though that is unlikely to be an option on a hosted provider like AKS. So that would leave you with using a userspace proxy that supports gRPC like Traefik or Istio Ingress. Picking one is out of scope for SO but most of those proxies support some kind of connection stickiness of some form.</p>
