<p>I have a gRPC microservice running within Kubernetes, currently there is only one pod, I want to increase the number of pods for the microservice, but in order to do that I want to route the same key to the same pod always, so as to avoid race conditions, I would like to understand how to achieve this functionality.</p>

user37940
<p>In this case you need layer 7 (L7) load balancer because they operate at the application layer and can inspect traffic in order to make routing decisions. Most importantly, they can support the HTTP/2 protocol (which gRPC uses).</p>

<p>Nginx and HAProxy are one of the options for L7 load balancers, but too heavyweight to microservice architecture. You can think about <a href="https://www.envoyproxy.io/docs/envoy/latest/start/start" rel="nofollow noreferrer">Envoy</a> and <a href="https://linkerd.io/2/getting-started/" rel="nofollow noreferrer">Linkerd</a>, both have support for gRPC.</p>

<p>Pods can be replicated to provide scaling and are wrapped in abstractions known as services which provide a stable IP address for accessing the underlying pods. Since Kubernetes 1.2 the default behaviour on hitting a service IP is that a random backend pod will be returned. However you can reconfigure your services to be headless so that the service IP will instead return the entire list of available pod IPs, allowing you to perform your own service discovery.</p>

<p>You can easily start with Linkerd with this <a href="https://linkerd.io/2/getting-started/" rel="nofollow noreferrer">official tutorial</a>.</p>
