Deterministic routing with key to a gRPC service in Kubernetes

9/19/2019

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.

-- user37940
grpc
kubernetes
routing

1 Answer

9/23/2019

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).

Nginx and HAProxy are one of the options for L7 load balancers, but too heavyweight to microservice architecture. You can think about Envoy and Linkerd, both have support for gRPC.

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.

You can easily start with Linkerd with this official tutorial.

-- muscat
Source: StackOverflow