Kubernetes 为同一端口上的不同路径匹配Istio虚拟服务路由

Kubernetes 为同一端口上的不同路径匹配Istio虚拟服务路由,kubernetes,istio,Kubernetes,Istio,我想知道如何在同一端口上匹配gRPC路由。下面是我希望通过我的VirtualService实现的一个示例: apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: istio-ingress spec: hosts: - "*" gateways: - istio-gateway http: - match: - uri: prefix: "/cus

我想知道如何在同一端口上匹配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,然后将请求分离到专门的内部服务。将来我可能会进一步分离服务(不仅仅是流媒体)。也就是说,端点的整个组可能由单独的集群处理


当我部署此规则时,整个VS似乎出现故障,没有任何响应。

端口在
入口网关中暴露在外部,应使用
网关进行内部配置。
VirtualService
仅用于第7层路由(一旦连接到
网关

match
配置中,您指定的是寻址主机应该在端口31400中接收请求,而不是服务正在侦听。发件人:

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

在您的情况下,您可能需要创建一个新的
网关
,以处理暴露端口的配置,然后使用
虚拟服务连接路由部分

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

由于
匹配
,您需要在它前面加上前缀,以拾取除上一个URI精确匹配之外的任何内容。

以下是我的观察结果:

  • VirtualService->
    http.match.port
    。我认为这里没有正确使用
    端口。如果这表示侦听端口31400的传入请求,那么这实际上应该在网关YAML规范
    istio Gateway
  • 请共享名为
    istio Gateway
    的网关规范。基本上,您可以在这里指定您正在侦听的端口号:31400
  • 。VirtualService是您指示要路由到哪个服务/主机和端口或“分离请求”的位置 请检查一下是否有用