I want to access dynamic value in VirtualService for uri

1/31/2020

I want to deploy two services with different URLs.

 - match:
      uri:
        prefix: /pune
    route:
    - destination:
        host: wagholi
        port:
          number: 8080
 - match:
      uri:
        prefix: /pune/{location}
    route:
    - destination:
        host: yerwada
        port:
          number: 8080
 - match:              
      uri:
        prefix: /pune/{local}/here
    route:
    - destination:
        host: hadapsar
        port:
          number: 8080

In this scenario, When I am hitting API getting 404 Not Found /pune/yerwada when I pass location value as yerwada. Also I am passing /pune/hadapsar/here getting same error 404 Not Found /pune/hadapsar/here, When I pass hadapsar at the place of local. !!!!!

-- Balkrishna
gateway
istio
kubernetes
kubernetes-ingress
routing

2 Answers

2/3/2020

We can go with regex for uri.

 - match:
      uri:
        prefix: /pune
    route:
    - destination:
        host: wagholi
        port:
          number: 8080
 - match:
      uri:
        regex: \/pune/\/(.+)
    route:
    - destination:
        host: yerwada
        port:
          number: 8080
 - match:              
      uri:
        prefix: \/pune\/(.+)\/here
    route:
    - destination:
        host: hadapsar
        port:
          number: 8080
-- Balkrishna
Source: StackOverflow

1/31/2020

Do the requests pass in a header named location with value of pune? If "no" then remove this from the matching rules - it is the cause for the requests not being matched by uri prefix alone:

    - headers:
        location:
          exact: pune

Just in case, here is a link to the relevant doc.

-- gears
Source: StackOverflow