【问题标题】:How can I use Envoy to route /some-prefix to a gRPC service appropriately?如何使用 Envoy 将 /some-prefix 适当地路由到 gRPC 服务?
【发布时间】:2020-11-26 05:10:10
【问题描述】:

我正在尝试设置 Envoy 以将 "/account" 路由到 gRPC 服务。如果我将路由前缀设置为"/",它工作正常,但如果我引入"/account",它会中断。我试过prefix_rewrite:"/",但没有帮助。

admin:
  access_log_path: /tmp/admin_access.log
  address:
    socket_address: { address: 0.0.0.0, port_value: 9901 }
static_resources:
  listeners:
    - name: listener_0
      address:
        socket_address: { address: 0.0.0.0, port_value: 3000 }
      filter_chains:
        - filters:
            - name: envoy.filters.network.http_connection_manager
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
                codec_type: auto
                stat_prefix: ingress_http
                route_config:
                  name: local_route
                  virtual_hosts:
                    - name: local_service
                      domains: ["*"]
                      routes:
                        - match: { prefix: "/account/" }
                          route: {cluster: account_service, prefix_rewrite: "/" }
                        - match: { prefix: "/account" }
                          route: { cluster: account_service, prefix_rewrite: "/"}
                            
                http_filters:
                  - name: envoy.filters.http.grpc_web
                  - name: envoy.filters.http.router
  clusters:
    - name: account_service
      connect_timeout: 0.25s
      type: logical_dns
      http2_protocol_options: {}
      lb_policy: round_robin
      hosts: [{ socket_address: { address: account, port_value: 3400 } }]

点击localhost:3000/account 会导致:

{
  "error": "14 UNAVAILABLE: DNS resolution failed"
}

感谢您的宝贵时间。我知道它很有价值!

【问题讨论】:

    标签: proxy grpc envoyproxy


    【解决方案1】:

    prefix_rewrite 不起作用,因为它会将 localhost:3000/account 路由到 account_service:3400/。只需在您的情况下,这应该可以工作。这应该将 localhost:3000/account 路由到 account_service:3400/account

    - match: { prefix: "/account/" }
      route: {cluster: account_service}
    

    【讨论】:

    • 很遗憾没有。这就是我开始的地方。我认为问题在于它以 localhost:3000/ 结尾,但我想不出一种在重写时删除尾部斜杠的方法。 prefix_rewrite: "" 只是被忽略了
    • 这最终成为我使用 Bloom 进行测试的问题。
    猜你喜欢
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-25
    • 1970-01-01
    • 2019-09-06
    • 1970-01-01
    相关资源
    最近更新 更多