首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >匹配相同端口上不同路径的Istio虚拟服务路由

匹配相同端口上不同路径的Istio虚拟服务路由
EN

Stack Overflow用户
提问于 2019-08-14 20:09:54
回答 2查看 2.1K关注 0票数 0

我想知道如何才能匹配同一端口上的gRPC路由。下面是我希望用我的VirtualService完成的一个例子:

代码语言:javascript
复制
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,然后将请求分割成一个专用的内部服务。在未来,我可能会进一步拆分服务(而不仅仅是流)。即。端点的整个组可以由单独的集群处理。

但是,当我部署这个规则时,整个VS似乎失败了,没有任何响应。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-08-27 16:05:51

端口是在Ingressgateway中对外公开的,应该使用Gateway进行内部配置。VirtualService只用于第7层路由(一旦连接到Gateway)。

在您的match配置中,您指定被寻址的主机应该在端口31400中接收请求,而不是在那里侦听服务。来自文献资料

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

在您的示例中,您可能希望创建一个新的Gateway来处理公开端口的配置,然后使用VirtualService附加路由部分

代码语言:javascript
复制
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

由于match 不能是空的,除了前面的URI完全匹配之外,您需要为它加上前缀以获取将要出现的任何内容。

票数 1
EN

Stack Overflow用户

发布于 2019-08-30 02:29:55

以下是我的观察:

  1. VirtualService -> http.match.port.我认为port在这里的用法不正确。如果这是为了指示侦听传入的请求到端口31400,那么这实际上应该在网关YAML规范istio-gateway中。
  2. 请分享您的网关名为istio-gateway的规范。基本上,在那里您指定您正在侦听port.number: 31400。VirtualService是您指示要路由或“断开请求”的服务/主机和端口的位置。

请检查一下,看看是否有用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57501384

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档