VirtualService: HTTPMatchRequest based on URI as well as Headers

My requirement is to route incoming request to appropriate service based on BOTH -

  • Match URI
  • Match One of the Request Header

Here is the VirtualService -

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: adhello-vs
  namespace: test-sales
spec:
  hosts:
  - "*"
  gateways:
  - spectra-istio-config-gateway.istio-system.svc.cluster.local
  http:
  - match:
    - uri:
        prefix: /greet/
    - headers:
        Product:
          exact: Sales
    route:
    - destination:
        host: adhello-svc.test-sales.svc.cluster.local
        port:
          number: 8080

But then the Header match Product=Sales does not seem to take any effect. Can someone pls help to understand what am I missing ?

Followed the example here and it worked -

@adurai81 Have you figured out what was the problem? Just had the same issue

If anyone is looking for the solution, the fix is to have “headers” under the match condition.

http:
  - match:
    - uri:
        prefix: /greet/
    - headers:
        Product:
          exact: Sales
http:
  - match:
    - uri:
        prefix: /greet/
      headers:
        Product:
          exact: Sales
1 Like