Domain and path-based VirtualServices for same microservices

Hello everyone!

I have a concrete use-case which seems to be difficult to implement, or at least I don’t really know how.

I have several services (Service A, Service B and Service C) which have been accessed up until now as:

- serviceA.api.dacamposol.com
- serviceB.api.dacamposol.com
- serviceC.api.dacamposol.com

For that, I had a VirtualService for each of them with some rules, concretely ones which use regex for the HTTPMatchRequest (and no HTTPRewrite).

Now, for a customer’s request, I would like to have those services available as well on:

- api.dacamposol.com/serviceA
- api.dacamposol.com/serviceB
- api.dacamposol.com/serviceC

Problem is, that I cannot keep the same Rules that I had, because the HTTPRewrite doesn’t admit regex types, so what for the subdomain-match logic would be:

match:
- uri: 
    regex: <MY_REGEX>

Cannot be transformed in the path-match logic to:

match:
- uri: 
    regex: /serviceA/<MY_REGEX>
rewrite:
  uri: /<MY_REGEX>

I tried to do a VirtualService-chain by taking as .spec.host the destination from .spec.http[].destination but it doesn’t seem to work:

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
spec:
  hosts:
  - api.dacamposol.com
  http:
  - match:
    - uri:
        prefix: /serviceA/
    - uri:
        exact: /serviceA
    rewrite:
      uri: "/"
    route:
      - destination:
          host: serviceA.default.svc.cluster.local
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
spec:
  hosts:
  - serviceA.api.dacamposol.com
  http:
  - name: default
    route:
      - destination:
          host: serviceA.default.svc.cluster.local
---  
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
spec:
  hosts:
  - serviceA.default.svc.cluster.local
  http:
  - match:
     - uri: 
        regex: <MY_REGEX>
    route:
      - destination:
          host: serviceA.default.svc.cluster.local

Has someone ever faced something similar or does how to approach this?