因grpc请求量巨大,且集中到一个pod上压力较大。故采用nginx作为grpc服务的负载均衡。
经查,Nginx官方宣布nginx 1.13.10支持gRPC。所以我们仅需要对配置文件进行相应配置即可。配置如下:
server {
listen 80 http2;
server_name localhost;
location / {
grpc_pass grpc://mygrpc-server:60055;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
经测,请求轮流发送到多个grpc server。实现了负载均衡。