How to use variables in Istio VirtualService?

Hi. I’m currently working on a case when we need to dynamically create services and provide access to them via URI subpaths of the main gateway.

I’m planning to use virtual services for traffic routing for them. Virtual Service for a particular service should look like:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: subpaths-routes
spec:
hosts:

  • mainservice.prod.svc.cluster.local
    http:
  • name: “subpath-redirection”
    match:
    • uri:
      prefix: “/bservices/svc-2345-6789”
      route:
    • destination:
      host: svc-2345-6789.prod.svc.cluster.local

But there may be a huge number of such services (like thousands). All follow the same pattern of routing.
I would like to know if Istio has a mechanism to specify VirtualService with variables/parameters like the following:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: subpaths-routes
spec:
hosts:

  • mainservice.prod.svc.cluster.local
    http:
  • name: “subpath-redirection”
    match:
    • uri:
      prefix: “/bservices/”{{ variable }}
      route:
    • destination:
      host: {{ variable }}.prod.svc.cluster.local

In Nginx, one can do a similar thing by specifying something like this:

location ~ /service/(?[0-9a-zA-Z_-]+)/ {
proxy_pass http://:8080$variable;
}

Is there a way in Istio to accomplish that?
And if there is not, how would thousands of VSs impact the performance of request processing? Is It expensive to keep them in terms of CPU and RAM being consumed?

Thank you in advance!

Did you find a solution? I’m having the same problem and I can’t believe that you were never answered.

URI to match values include “ regex”

- match:
    - uri:
        regex: /bservices/*
    route:
    - destination:
        host: prod

but destination not support loadbalance by variable, one match rule must assign specific cause envoy logic component is different by nginx :grinning:

istio does not support path variables. So * asterisk must be used as a regex to specify path-variables.
Please correct if wrong and share if any other solution is possible