<p>I have read the Load Balancing page at <a href="https://github.com/grpc/grpc/blob/master/doc/load-balancing.md" rel="noreferrer">https://github.com/grpc/grpc/blob/master/doc/load-balancing.md</a> to start of, but still am confused as to the right approach to loadbalancing between back end GRPC instances.  We are deploying multiple gRPC 'microservice' instances and want our other gRPC clients to be able to be routed between them.  We are deploying these as pods in kubernetes (actually Google Container Engine).</p>

<p>Can anyone explain the 'recommended' approach to loadbalancing gRPC client requests between the gRPC servers? It seems that clients need to be aware of the endpoints - is it not possible to take advantage of the inbuilt LoadBalancer in Container Engine to help?</p>

<p>I can't talk about kubernetes, but regarding gRPC loadbalancing, there are basically two approaches:</p>

<ol>
<li>For simple usecases, you can enable round robin over the list of addresses returned for a given name (ie, the list of IPs returned for service.foo.com). The way to do this is language-dependent. For C++, you'd use <a href="http://www.grpc.io/grpc/cpp/classgrpc_1_1_channel_arguments.html#a860058f6b9fa340bb2075ae113e423a6" rel="noreferrer"><code>grpc::ChannelArguments::SetLoadBalancingPolicyName</code></a> with "round_robin" as the argument (in the future it'd also be possible to select via "<a href="https://github.com/grpc/grpc/blob/master/doc/service_config.md" rel="noreferrer">service configuration</a>", but the design for how to encode that config in DNS records hasn't been finalized yet).</li>
<li>Use the grpclb protocol. This is suitable for more complex deployements. This feature required the <a href="https://c-ares.haxx.se/" rel="noreferrer">c-ares DNS resolver</a>, which <a href="https://github.com/grpc/grpc/pull/11237" rel="noreferrer">#11237</a> introduces (this PR is very close to being merged). This is the piece that's missing for making grpclb work in open source. In particular:

<ul>
<li>Have a look at <a href="https://github.com/grpc/proposal/blob/master/A5-grpclb-in-dns.md" rel="noreferrer">this document</a>. It goes over the DNS configuration changes needed to control which addresses are marked as balancers. It's currently a "proposal", to be promoted to a doc shortly. It can be taken quite authoritatively, it's what <a href="https://github.com/grpc/grpc/pull/11237" rel="noreferrer">#11237</a> is implementing for balancer discovery.</li>
<li>Write a regular gRPC server (in any language) implementing <a href="https://github.com/grpc/grpc/blob/master/src/proto/grpc/lb/v1/load_balancer.proto" rel="noreferrer">the load balancer protocol</a>. This is the server to be marked in your DNS records as a balancer (as described in <a href="https://github.com/grpc/proposal/blob/master/A5-grpclb-in-dns.md" rel="noreferrer">the aforementioned document</a>), with which the client's grpclb will talk to to obtain the list of backend addresses (what's called <a href="https://github.com/grpc/grpc/blob/master/src/proto/grpc/lb/v1/load_balancer.proto#L120" rel="noreferrer">server_lists</a>). It's up to you to make the logic inside this balancer as simple or as complex as you want.</li>
<li>The client would use the DNS name of the <em>balancer</em> when creating a channel. Note also that your balancer DNS name may point to several addresses. If one or more of them are marked as balancers, grpclb will be used. Which balancer will be picked up if there's more than one? The first one the client connects to.</li>
</ul></li>
</ol>

<p>Let me know if you have any questions.</p>
