【问题标题】:Match Istio Virtual Services routes for different paths on same port为同一端口上的不同路径匹配 Istio 虚拟服务路由
【发布时间】:2019-12-21 09:44:26
【问题描述】:

我想知道如何在同一端口上匹配 gRPC 路由。这是我希望通过 VirtualService 完成的一个示例:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: istio-ingress
spec:
  hosts:
  - "*"
  gateways:
  - istio-gateway
  http:
  - match:
    - uri:
      prefix: "/custom.api/stream"
    - port: 31400
    route:
    - destination:
        host: stream-handler.default.svc.cluster.local
        port:
          number: 8444
    timeout: 60s
    retries:
      attempts: 3
      perTryTimeout: 2s
  - match:
    - port: 31400
    route:
    - destination:
        host: api.default.svc.cluster.local
        port:
          number: 8443
    timeout: 60s
    retries:
      attempts: 3
      perTryTimeout: 2s

所以基本上:对于进入 31400 的所有请求,第一个匹配项会在“/custom.api/stream”处寻找流式传输请求,该请求具有我的流服务器的目的地。

第二条规则是获取我的主要 API 的入口。

我的目标是让所有连接都通过 31400,然后将请求拆分到专用的内部服务。将来我可能会进一步拆分服务(不仅仅是流媒体)。 IE。整个端点组可能由单独的集群处理。

当我部署此规则时,虽然整个 VS 似乎失败并且没有任何响应。

【问题讨论】:

    标签: kubernetes istio


    【解决方案1】:

    端口在Ingressgateway 中对外公开,​​应使用Gateway 在内部进行配置。 VirtualService 仅用于第 7 层路由(一旦附加到 Gateway)。

    在您的 match 配置中,您指定 寻址 主机应在端口 31400 中接收请求,而不是服务正在那里侦听。来自the documentation

    端口:指定正在寻址的主机上的端口。许多服务只公开一个端口或使用它们支持的协议标记端口,在这些情况下,不需要显式选择端口。

    在您的情况下,您可能需要创建一个新的Gateway 来处理暴露端口的配置,然后使用您的VirtualService 附加路由部分:

    apiVersion: networking.istio.io/v1alpha3
    kind: Gateway
    metadata:
      name: grpc-gateway
    spec:
      selector:
        istio: ingressgateway
      servers:
      - port:
          number: 31400
          name: grpc
          protocol: GRPC
        hosts:
        - "*"
    ---
    apiVersion: networking.istio.io/v1alpha3
    kind: VirtualService
    metadata:
      name: grpc-virtualservice
    spec:
      hosts:
      - "*"
      gateways:
      - grcp-gateway
      http:
      - match:
        - uri:
          exact: "/custom.api/stream"
        route:
        - destination:
            host: stream-handler.default.svc.cluster.local
            port:
              number: 8444
        timeout: 60s
        retries:
          attempts: 3
          perTryTimeout: 2s
      - match:
        - uri:
          prefix: "/"
        route:
        - destination:
            host: api.default.svc.cluster.local
            port:
              number: 8443
        timeout: 60s
        retries:
          attempts: 3
          perTryTimeout: 2s
    

    由于matchcannot be empty,您需要为其添加前缀,以获取除了之前的URI精确匹配之外的任何内容。

    【讨论】:

      【解决方案2】:

      以下是我的观察:

      1. 虚拟服务->http.match.port。我认为port 在这里使用不正确。如果这应该表明正在侦听对端口 31400 的传入请求,那么这实际上应该在 Gateway YAML 规范istio-gateway 中。
      2. 请分享您的网关规格istio-gateway。基本上,您可以在此处指定您正在收听port.number: 31400。 VirtualService 是您指示要路由或“分离请求”的服务/主机和端口的位置。

      请检查一下是否有帮助。

      【讨论】:

        猜你喜欢
        • 2021-03-25
        • 1970-01-01
        • 2013-10-06
        • 2020-11-09
        • 2019-07-06
        • 2022-01-20
        • 1970-01-01
        • 1970-01-01
        • 2020-12-05
        相关资源
        最近更新 更多