title: How to use variables in Istio VirtualService?
body: <p>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.</p>
  <p>I'm planning to use virtual services for traffic routing for them.  Virtual Service for a particular service should look like:</p>
  <pre><code>apiVersion: networking.istio.io/v1alpha3
  kind: VirtualService
  metadata:
    name: subpaths-routes
  spec:
    hosts:
    - mainservice.prod.svc.cluster.local
    http:
    - name: &quot;subpath-redirection&quot;
      match:
      - uri:
          prefix: &quot;/bservices/svc-2345-6789&quot;
      route:
      - destination:
          host: svc-2345-6789.prod.svc.cluster.local
  </code></pre>
  <p>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:</p>
  <pre><code>apiVersion: networking.istio.io/v1alpha3
  kind: VirtualService
  metadata:
    name: subpaths-routes
  spec:
    hosts:
    - mainservice.prod.svc.cluster.local
    http:
    - name: &quot;subpath-redirection&quot;
      match:
      - uri:
          prefix: &quot;/bservices/&quot;{{ variable }}
      route:
      - destination:
          host: {{ variable }}.prod.svc.cluster.local
  </code></pre>
  <p>In Nginx, one can do a similar thing by specifying something like this:</p>
  <pre><code>location ~ /service/(?&lt;variable&gt;[0-9a-zA-Z\_\-]+)/ {
    proxy_pass http://$variable:8080;
  }
  </code></pre>
  <p>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?</p>
  <p>Thank you in advance!</p>