【问题标题】:gRPC service endpoint is not accessible via Kong Gateway无法通过 Kong Gateway 访问 gRPC 服务端点
【发布时间】:2020-08-16 18:29:18
【问题描述】:

gRPC 服务(在 springboot 中开发)部署为 AWS linux (ec2) 上的 docker 容器。使用端口转发 -p6565:6565 启动 docker 映像。 现在通过笔记本电脑上的 BloomRPC 直接点击时,它可以工作:ec2.IP:6565 Package.Service.Method

在 Kong 配置的服务和路线:

{
            "host": "ec2.IP",
            "created_at": 1588403433,
            "connect_timeout": 60000,
            "id": "e657d8df-6247-458a-a8e8-bec00c41e03c",
            "protocol": "grpc",
            "name": "aws-grpc1",
            "read_timeout": 60000,
            "port": 6565,
            "path": null,
            "updated_at": 1588403433,
            "retries": 5,
            "write_timeout": 60000,
            "tags": null,
            "client_certificate": null
}

Route:
{
            "strip_path": false,
            "path_handling": "v0",
            "updated_at": 1588403452,
            "destinations": null,
            "headers": null,
            "protocols": [
                "grpc",
                "grpcs"
            ],
            "created_at": 1588403452,
            "snis": null,
            "service": {
                "id": "e657d8df-6247-458a-a8e8-bec00c41e03c"
            },
            "name": "aws-grpc1-route1",
            "methods": null,
            "preserve_host": false,
            "regex_priority": 0,
            "paths": [
                "/grpc2"
            ],
            "sources": null,
            "id": "5739297e-3be7-4a0d-8afb-cfa8ed01cec2",
            "https_redirect_status_code": 426,
            "hosts": null,
            "tags": null
        }

现在通过 grpcurl 击中它 -> 它不起作用:

grpcurl -v -d "{}" -insecure ec2.ip:8443 package.service.pingMethod

Error invoking method "package.service.ping": target server does not expose service "package.service"

这是看起来相关的 kong 配置:

"proxy_listen": [
            "0.0.0.0:8000 reuseport backlog=16384",
            "0.0.0.0:8443 **http2** ssl reuseport backlog=16384"
        ],

所以这里是查询: (1) 8000 也可以为 https 配置为不安全 -> 通过在 kong-container 启动时传递一个 env KONG_PROXY_LISTEN 变量

    -e "KONG_PROXY_LISTEN=0.0.0.0:8000 http2, 0.0.0.0:8443 http2 ssl" 

这样做好吗?

(2) 如何开启服务器端反射?或者 /grpc.reflection.v1alpha.ServerReflection/ServerReflectionInfo 有什么用?

【问题讨论】:

    标签: grpc api-gateway grpc-java kong


    【解决方案1】:

    您需要为 Kong 公开 HTTP2 代理侦听器。 你可以参考这个:https://konghq.com/blog/manage-grpc-services-kong/

    简而言之,您需要像这样为KONG_PROXY_LISTEN 添加环境变量详细信息:

    -e "KONG_PROXY_LISTEN=0.0.0.0:8000 http2, 0.0.0.0:8443 http2 ssl, 0.0.0.0:9080 http2, 0.0.0.0:9081 http2 ssl" 
    

    注意:显然 Kong 使用端口 9080 用于 HTTP2 和 9081 用于 HTTP2 SSL。但我认为这是可以改变的。

    并且还像这样公开那些 9080 和 9081 端口,这是docker run 命令的示例:

    -p 127.0.0.1:9080:9080 \
    -p 127.0.0.1:9081:9081 
    

    当你尝试请求时,使用grpcurl 中的 9080 端口,如下所示:

    grpcurl -v -d '{"name": "Ken"}' -plaintext localhost:9080 facade.GreetingService/SayHello
    

    【讨论】:

      【解决方案2】:

      更多更新:

      在 kong.ingress 后面部署的 gRPC 工作正常:

      grpcurl -v -d "{\"greeting\":\"111\"}" -insecure acfb0xxxxx.elb.us-east-2.amazonaws.com:443 hello.HelloService.SayHello
      

      回复:

      Resolved method descriptor:
      rpc SayHello ( .hello.HelloRequest ) returns ( .hello.HelloResponse );
      
      Request metadata to send:
      (empty)
      
      Response headers received:
      content-type: application/grpc
      date: Sat, 02 May 2020 07:00:17 GMT
      server: openresty
      trailer: Grpc-Status
      trailer: Grpc-Message
      trailer: Grpc-Status-Details-Bin
      via: kong/2.0.3
      x-kong-proxy-latency: 1
      x-kong-upstream-latency: 9
      
      Response contents:
      {
        "reply": "hello 111"
      }
      
      Response trailers received:
      (empty)
      Sent 1 request and received 1 response
      

      在 kong-API-gateway 上配置时,它不起作用:

      grpcurl -v -d "{\"greeting\":\"111\"}" -insecure kong.ce-gateway.ip:8443 hello.HelloService.SayHello
      Error invoking method "hello.HelloService.SayHello": failed to query for service descriptor "hello.HelloService": rpc error: code = Internal desc = An invalid response was received from the upstream server
      

      【讨论】:

      • gRPC服务部署和通过kong-gateway暴露有没有好的教程?
      【解决方案3】:

      现在默认为 Kong 启用 Http2,但如果您遇到问题,最好从检查全局配置的 proxy_listeners 部分开始。就我而言,我发现 http2 仅对 SSL 端口启用,而不是对非 SSL 启用。查看全局配置的一个好方法是向 admin api 的根 url 发送 GET 请求,例如GET http://localhost:8001/

      【讨论】:

        猜你喜欢
        • 2020-05-07
        • 1970-01-01
        • 1970-01-01
        • 2019-01-30
        • 2017-12-01
        • 2019-03-09
        • 1970-01-01
        • 1970-01-01
        • 2017-12-05
        相关资源
        最近更新 更多