是否可以在单个网关中设置共享同一主机的多个VirtualService?

时间:2019-02-13 03:53:03

标签: kubernetes istio

假设我有VirtualService Foo,该服务器具有管理team.company.com/foo http路径的规则,并将其绑定到网关TeamGateway(具有主机team.company.com)。 然后引入另一个VirtualService Bar,以管理到特定后端的team.company.com/bar规则路径,并绑定到同一网关TeamGateway。有可能吗?

1 个答案:

答案 0 :(得分:0)

您很可能可以通过匹配uri前缀甚至使用1个VirtualService来做到这一点。

Gateway应该看起来像:

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: your-new-gateway
spec:
  selector:
    app: your-new-gateway-controller
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - team.company.com

定义网关后,创建VirtualService并将其匹配到不同的前缀:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: vs-rule
spec:
  hosts:
  - team.company.com
  gateways:
  - your-new-gateway
  http:
  - match:
      uri:
        prefix: /foo/
    route:
    - destination:
        host: your_1.svc.cluster.local #Kubernetes underlying service name
  - match:
      uri:
        prefix: /bar/
    route:
    - destination:
        host: your_2.svc.cluster.local #Kubernetes underlying service name