How to configure Istio virtual service to route traffic based on different domain names

Hey Team,

I have been trying to configure Istio’s virtual service to route the traffic based on the domain names. I have an Azure application load balancer configured as Ingress gateway and the application gateway is installed as Azure AKS addon. I have added the A records for these two domains.

I am deploying the same application in different namespaces. My requirement is when I access https://dev.example.com/app1 it should hit the application(app1) running in the ‘dev’ name space and if I access https://qa.example.com/app1 it should hit the application running in the ‘qa’ namespace.

Right now the traffic is getting routed only to https://dev.example.com/app1 even when I try to access the other url.

Attaching the configuration which we are using:


apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: components
  spec:
  hosts:
  - "dev.example.com"
  gateways:
  - my-gateway
  http:
  - match:
    - uri:
        prefix: /app1
    timeout: 60s
    route:
    - destination:
        port:
          number: 80
        host: app1.dev.svc.cluster.local

---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: apps
 spec:
  hosts:
  - "qa.example.com"
  gateways:
  - my-gateway
  http:
  - match:
    - uri:
        prefix: /app1
    timeout: 60s
    route:
    - destination:
        port:
          number: 80
        host: app1.qa.svc.cluster.local

Any help is appreciated.

Regards,
Kiran Udayan