Is it possible to setup multiple VirtualService that share same host in a single Gateway?

2/13/2019

Let say I have VirtualService Foo that has rule to manage team.company.com/foo http path, and bind it to the Gateway TeamGateway (that has host team.company.com). Then introduce another VirtualService Bar to manage team.company.com/bar rule path to certain backend, bind to the same Gateway TeamGateway. Is it possible?

-- Agung Pratama
istio
kubernetes

1 Answer

2/13/2019

Most probably you can do this by matching the uri prefix and even using 1 VirtualService.

Gateway should look like:

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

After defining Gateway you create VirtualService matching it to different prefixes:

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
-- VKR
Source: StackOverflow