Virtual Service

Configuration affecting traffic routing. Here are a few terms useful to define in the context of traffic routing.

Service a unit of application behavior bound to a unique name in a service registry. Services consist of multiple network endpoints implemented by workload instances running on pods, containers, VMs etc.

Service versions (a.k.a. subsets) - In a continuous deployment scenario, for a given service, there can be distinct subsets of instances running different variants of the application binary. These variants are not necessarily different API versions. They could be iterative changes to the same service, deployed in different environments (prod, staging, dev, etc.). Common scenarios where this occurs include A/B testing, canary rollouts, etc. The choice of a particular version can be decided based on various criterion (headers, url, etc.) and/or by weights assigned to each version. Each service has a default version consisting of all its instances.

Source - A downstream client calling a service.

Host - The address used by a client when attempting to connect to a service.

Access model - Applications address only the destination service (Host) without knowledge of individual service versions (subsets). The actual choice of the version is determined by the proxy/sidecar, enabling the application code to decouple itself from the evolution of dependent services.

A VirtualService defines a set of traffic routing rules to apply when a host is addressed. Each routing rule defines matching criteria for traffic of a specific protocol. If the traffic is matched, then it is sent to a named destination service (or subset/version of it) defined in the registry.

The source of traffic can also be matched in a routing rule. This allows routing to be customized for specific client contexts.

The following example on Kubernetes, routes all HTTP traffic by default to pods of the reviews service with label “version: v1”. In addition, HTTP requests with path starting with /wpcatalog/ or /consumercatalog/ will be rewritten to /newcatalog and sent to pods with label “version: v2”.

  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: VirtualService
  3. metadata:
  4. name: reviews-route
  5. spec:
  6. hosts:
  7. - reviews.prod.svc.cluster.local
  8. http:
  9. - name: "reviews-v2-routes"
  10. match:
  11. - uri:
  12. prefix: "/wpcatalog"
  13. - uri:
  14. prefix: "/consumercatalog"
  15. rewrite:
  16. uri: "/newcatalog"
  17. route:
  18. - destination:
  19. host: reviews.prod.svc.cluster.local
  20. subset: v2
  21. - name: "reviews-v1-route"
  22. route:
  23. - destination:
  24. host: reviews.prod.svc.cluster.local
  25. subset: v1
  1. apiVersion: networking.istio.io/v1beta1
  2. kind: VirtualService
  3. metadata:
  4. name: reviews-route
  5. spec:
  6. hosts:
  7. - reviews.prod.svc.cluster.local
  8. http:
  9. - name: "reviews-v2-routes"
  10. match:
  11. - uri:
  12. prefix: "/wpcatalog"
  13. - uri:
  14. prefix: "/consumercatalog"
  15. rewrite:
  16. uri: "/newcatalog"
  17. route:
  18. - destination:
  19. host: reviews.prod.svc.cluster.local
  20. subset: v2
  21. - name: "reviews-v1-route"
  22. route:
  23. - destination:
  24. host: reviews.prod.svc.cluster.local
  25. subset: v1

A subset/version of a route destination is identified with a reference to a named service subset which must be declared in a corresponding DestinationRule.

  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: DestinationRule
  3. metadata:
  4. name: reviews-destination
  5. spec:
  6. host: reviews.prod.svc.cluster.local
  7. subsets:
  8. - name: v1
  9. labels:
  10. version: v1
  11. - name: v2
  12. labels:
  13. version: v2
  1. apiVersion: networking.istio.io/v1beta1
  2. kind: DestinationRule
  3. metadata:
  4. name: reviews-destination
  5. spec:
  6. host: reviews.prod.svc.cluster.local
  7. subsets:
  8. - name: v1
  9. labels:
  10. version: v1
  11. - name: v2
  12. labels:
  13. version: v2

VirtualService

Configuration affecting traffic routing.

FieldTypeDescriptionRequired
hostsstring[]

The destination hosts to which traffic is being sent. Could be a DNS name with wildcard prefix or an IP address. Depending on the platform, short-names can also be used instead of a FQDN (i.e. has no dots in the name). In such a scenario, the FQDN of the host would be derived based on the underlying platform.

A single VirtualService can be used to describe all the traffic properties of the corresponding hosts, including those for multiple HTTP and TCP ports. Alternatively, the traffic properties of a host can be defined using more than one VirtualService, with certain caveats. Refer to the Operations Guide for details.

Note for Kubernetes users: When short names are used (e.g. “reviews” instead of “reviews.default.svc.cluster.local”), Istio will interpret the short name based on the namespace of the rule, not the service. A rule in the “default” namespace containing a host “reviews” will be interpreted as “reviews.default.svc.cluster.local”, irrespective of the actual namespace associated with the reviews service. To avoid potential misconfigurations, it is recommended to always use fully qualified domain names over short names.

The hosts field applies to both HTTP and TCP services. Service inside the mesh, i.e., those found in the service registry, must always be referred to using their alphanumeric names. IP addresses are allowed only for services defined via the Gateway.

Note: It must be empty for a delegate VirtualService.

No
gatewaysstring[]

The names of gateways and sidecars that should apply these routes. Gateways in other namespaces may be referred to by <gateway namespace>/<gateway name>; specifying a gateway with no namespace qualifier is the same as specifying the VirtualService’s namespace. A single VirtualService is used for sidecars inside the mesh as well as for one or more gateways. The selection condition imposed by this field can be overridden using the source field in the match conditions of protocol-specific routes. The reserved word mesh is used to imply all the sidecars in the mesh. When this field is omitted, the default gateway (mesh) will be used, which would apply the rule to all sidecars in the mesh. If a list of gateway names is provided, the rules will apply only to the gateways. To apply the rules to both gateways and sidecars, specify mesh as one of the gateway names.

No
httpHTTPRoute[]

An ordered list of route rules for HTTP traffic. HTTP routes will be applied to platform service ports named ‘http-’/‘http2-’/‘grpc-’, gateway ports with protocol HTTP/HTTP2/GRPC/ TLS-terminated-HTTPS and service entry ports using HTTP/HTTP2/GRPC protocols. The first rule matching an incoming request is used.

No
tlsTLSRoute[]

An ordered list of route rule for non-terminated TLS & HTTPS traffic. Routing is typically performed using the SNI value presented by the ClientHello message. TLS routes will be applied to platform service ports named ‘https-’, ‘tls-’, unterminated gateway ports using HTTPS/TLS protocols (i.e. with “passthrough” TLS mode) and service entry ports using HTTPS/TLS protocols. The first rule matching an incoming request is used. NOTE: Traffic ‘https-’ or ‘tls-’ ports without associated virtual service will be treated as opaque TCP traffic.

No
tcpTCPRoute[]

An ordered list of route rules for opaque TCP traffic. TCP routes will be applied to any port that is not a HTTP or TLS port. The first rule matching an incoming request is used.

No
exportTostring[]

A list of namespaces to which this virtual service is exported. Exporting a virtual service allows it to be used by sidecars and gateways defined in other namespaces. This feature provides a mechanism for service owners and mesh administrators to control the visibility of virtual services across namespace boundaries.

If no namespaces are specified then the virtual service is exported to all namespaces by default.

The value “.” is reserved and defines an export to the same namespace that the virtual service is declared in. Similarly the value “” is reserved and defines an export to all namespaces.

No

Destination

Destination indicates the network addressable service to which the request/connection will be sent after processing a routing rule. The destination.host should unambiguously refer to a service in the service registry. Istio’s service registry is composed of all the services found in the platform’s service registry (e.g., Kubernetes services, Consul services), as well as services declared through the ServiceEntry resource.

Note for Kubernetes users: When short names are used (e.g. “reviews” instead of “reviews.default.svc.cluster.local”), Istio will interpret the short name based on the namespace of the rule, not the service. A rule in the “default” namespace containing a host “reviews will be interpreted as “reviews.default.svc.cluster.local”, irrespective of the actual namespace associated with the reviews service. To avoid potential misconfigurations, it is recommended to always use fully qualified domain names over short names.

The following Kubernetes example routes all traffic by default to pods of the reviews service with label “version: v1” (i.e., subset v1), and some to subset v2, in a Kubernetes environment.

  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: VirtualService
  3. metadata:
  4. name: reviews-route
  5. namespace: foo
  6. spec:
  7. hosts:
  8. - reviews # interpreted as reviews.foo.svc.cluster.local
  9. http:
  10. - match:
  11. - uri:
  12. prefix: "/wpcatalog"
  13. - uri:
  14. prefix: "/consumercatalog"
  15. rewrite:
  16. uri: "/newcatalog"
  17. route:
  18. - destination:
  19. host: reviews # interpreted as reviews.foo.svc.cluster.local
  20. subset: v2
  21. - route:
  22. - destination:
  23. host: reviews # interpreted as reviews.foo.svc.cluster.local
  24. subset: v1
  1. apiVersion: networking.istio.io/v1beta1
  2. kind: VirtualService
  3. metadata:
  4. name: reviews-route
  5. namespace: foo
  6. spec:
  7. hosts:
  8. - reviews # interpreted as reviews.foo.svc.cluster.local
  9. http:
  10. - match:
  11. - uri:
  12. prefix: "/wpcatalog"
  13. - uri:
  14. prefix: "/consumercatalog"
  15. rewrite:
  16. uri: "/newcatalog"
  17. route:
  18. - destination:
  19. host: reviews # interpreted as reviews.foo.svc.cluster.local
  20. subset: v2
  21. - route:
  22. - destination:
  23. host: reviews # interpreted as reviews.foo.svc.cluster.local
  24. subset: v1

And the associated DestinationRule

  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: DestinationRule
  3. metadata:
  4. name: reviews-destination
  5. namespace: foo
  6. spec:
  7. host: reviews # interpreted as reviews.foo.svc.cluster.local
  8. subsets:
  9. - name: v1
  10. labels:
  11. version: v1
  12. - name: v2
  13. labels:
  14. version: v2
  1. apiVersion: networking.istio.io/v1beta1
  2. kind: DestinationRule
  3. metadata:
  4. name: reviews-destination
  5. namespace: foo
  6. spec:
  7. host: reviews # interpreted as reviews.foo.svc.cluster.local
  8. subsets:
  9. - name: v1
  10. labels:
  11. version: v1
  12. - name: v2
  13. labels:
  14. version: v2

The following VirtualService sets a timeout of 5s for all calls to productpage.prod.svc.cluster.local service in Kubernetes. Notice that there are no subsets defined in this rule. Istio will fetch all instances of productpage.prod.svc.cluster.local service from the service registry and populate the sidecar’s load balancing pool. Also, notice that this rule is set in the istio-system namespace but uses the fully qualified domain name of the productpage service, productpage.prod.svc.cluster.local. Therefore the rule’s namespace does not have an impact in resolving the name of the productpage service.

  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: VirtualService
  3. metadata:
  4. name: my-productpage-rule
  5. namespace: istio-system
  6. spec:
  7. hosts:
  8. - productpage.prod.svc.cluster.local # ignores rule namespace
  9. http:
  10. - timeout: 5s
  11. route:
  12. - destination:
  13. host: productpage.prod.svc.cluster.local
  1. apiVersion: networking.istio.io/v1beta1
  2. kind: VirtualService
  3. metadata:
  4. name: my-productpage-rule
  5. namespace: istio-system
  6. spec:
  7. hosts:
  8. - productpage.prod.svc.cluster.local # ignores rule namespace
  9. http:
  10. - timeout: 5s
  11. route:
  12. - destination:
  13. host: productpage.prod.svc.cluster.local

To control routing for traffic bound to services outside the mesh, external services must first be added to Istio’s internal service registry using the ServiceEntry resource. VirtualServices can then be defined to control traffic bound to these external services. For example, the following rules define a Service for wikipedia.org and set a timeout of 5s for HTTP requests.

  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: ServiceEntry
  3. metadata:
  4. name: external-svc-wikipedia
  5. spec:
  6. hosts:
  7. - wikipedia.org
  8. location: MESH_EXTERNAL
  9. ports:
  10. - number: 80
  11. name: example-http
  12. protocol: HTTP
  13. resolution: DNS
  14. ---
  15. apiVersion: networking.istio.io/v1alpha3
  16. kind: VirtualService
  17. metadata:
  18. name: my-wiki-rule
  19. spec:
  20. hosts:
  21. - wikipedia.org
  22. http:
  23. - timeout: 5s
  24. route:
  25. - destination:
  26. host: wikipedia.org
  1. apiVersion: networking.istio.io/v1beta1
  2. kind: ServiceEntry
  3. metadata:
  4. name: external-svc-wikipedia
  5. spec:
  6. hosts:
  7. - wikipedia.org
  8. location: MESH_EXTERNAL
  9. ports:
  10. - number: 80
  11. name: example-http
  12. protocol: HTTP
  13. resolution: DNS
  14. ---
  15. apiVersion: networking.istio.io/v1beta1
  16. kind: VirtualService
  17. metadata:
  18. name: my-wiki-rule
  19. spec:
  20. hosts:
  21. - wikipedia.org
  22. http:
  23. - timeout: 5s
  24. route:
  25. - destination:
  26. host: wikipedia.org
FieldTypeDescriptionRequired
hoststring

The name of a service from the service registry. Service names are looked up from the platform’s service registry (e.g., Kubernetes services, Consul services, etc.) and from the hosts declared by ServiceEntry. Traffic forwarded to destinations that are not found in either of the two, will be dropped.

Note for Kubernetes users: When short names are used (e.g. “reviews” instead of “reviews.default.svc.cluster.local”), Istio will interpret the short name based on the namespace of the rule, not the service. A rule in the “default” namespace containing a host “reviews will be interpreted as “reviews.default.svc.cluster.local”, irrespective of the actual namespace associated with the reviews service. To avoid potential misconfiguration, it is recommended to always use fully qualified domain names over short names.

Yes
subsetstring

The name of a subset within the service. Applicable only to services within the mesh. The subset must be defined in a corresponding DestinationRule.

No
portPortSelector

Specifies the port on the host that is being addressed. If a service exposes only a single port it is not required to explicitly select the port.

No

HTTPRoute

Describes match conditions and actions for routing HTTP/1.1, HTTP2, and gRPC traffic. See VirtualService for usage examples.

FieldTypeDescriptionRequired
namestring

The name assigned to the route for debugging purposes. The route’s name will be concatenated with the match’s name and will be logged in the access logs for requests matching this route/match.

No
matchHTTPMatchRequest[]

Match conditions to be satisfied for the rule to be activated. All conditions inside a single match block have AND semantics, while the list of match blocks have OR semantics. The rule is matched if any one of the match blocks succeed.

No
routeHTTPRouteDestination[]

A HTTP rule can either redirect or forward (default) traffic. The forwarding target can be one of several versions of a service (see glossary in beginning of document). Weights associated with the service version determine the proportion of traffic it receives.

No
redirectHTTPRedirect

A HTTP rule can either redirect or forward (default) traffic. If traffic passthrough option is specified in the rule, route/redirect will be ignored. The redirect primitive can be used to send a HTTP 301 redirect to a different URI or Authority.

No
delegateDelegate

Delegate is used to specify the particular VirtualService which can be used to define delegate HTTPRoute.

It can be set only when Route and Redirect are empty, and the route rules of the delegate VirtualService will be merged with that in the current one.

NOTE:

  1. Only one level delegation is supported.
  2. The delegate’s HTTPMatchRequest must be a strict subset of the root’s, otherwise there is a conflict and the HTTPRoute will not take effect.
No
rewriteHTTPRewrite

Rewrite HTTP URIs and Authority headers. Rewrite cannot be used with Redirect primitive. Rewrite will be performed before forwarding.

No
timeoutDuration

Timeout for HTTP requests, default is disabled.

No
retriesHTTPRetry

Retry policy for HTTP requests.

No
faultHTTPFaultInjection

Fault injection policy to apply on HTTP traffic at the client side. Note that timeouts or retries will not be enabled when faults are enabled on the client side.

No
mirrorDestination

Mirror HTTP traffic to a another destination in addition to forwarding the requests to the intended destination. Mirrored traffic is on a best effort basis where the sidecar/gateway will not wait for the mirrored cluster to respond before returning the response from the original destination. Statistics will be generated for the mirrored destination.

No
mirrorPercentagePercent

Percentage of the traffic to be mirrored by the mirror field. If this field is absent, all the traffic (100%) will be mirrored. Max value is 100.

No
corsPolicyCorsPolicy

Cross-Origin Resource Sharing policy (CORS). Refer to CORS for further details about cross origin resource sharing.

No
headersHeaders

Header manipulation rules

No

Delegate

Describes the delegate VirtualService. The following routing rules forward the traffic to /productpage by a delegate VirtualService named productpage, forward the traffic to /reviews by a delegate VirtualService named reviews.

  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: VirtualService
  3. metadata:
  4. name: bookinfo
  5. spec:
  6. hosts:
  7. - "bookinfo.com"
  8. gateways:
  9. - mygateway
  10. http:
  11. - match:
  12. - uri:
  13. prefix: "/productpage"
  14. delegate:
  15. name: productpage
  16. namespace: nsA
  17. - match:
  18. - uri:
  19. prefix: "/reviews"
  20. delegate:
  21. name: reviews
  22. namespace: nsB
  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: VirtualService
  3. metadata:
  4. name: productpage
  5. namespace: nsA
  6. spec:
  7. http:
  8. - match:
  9. - uri:
  10. prefix: "/productpage/v1/"
  11. route:
  12. - destination:
  13. host: productpage-v1.nsA.svc.cluster.local
  14. - route:
  15. - destination:
  16. host: productpage.nsA.svc.cluster.local
  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: VirtualService
  3. metadata:
  4. name: reviews
  5. namespace: nsB
  6. spec:
  7. http:
  8. - route:
  9. - destination:
  10. host: reviews.nsB.svc.cluster.local
FieldTypeDescriptionRequired
namestring

Name specifies the name of the delegate VirtualService.

No
namespacestring

Namespace specifies the namespace where the delegate VirtualService resides. By default, it is same to the root’s.

No

Headers

Message headers can be manipulated when Envoy forwards requests to, or responses from, a destination service. Header manipulation rules can be specified for a specific route destination or for all destinations. The following VirtualService adds a test header with the value true to requests that are routed to any reviews service destination. It also removes the foo response header, but only from responses coming from the v1 subset (version) of the reviews service.

  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: VirtualService
  3. metadata:
  4. name: reviews-route
  5. spec:
  6. hosts:
  7. - reviews.prod.svc.cluster.local
  8. http:
  9. - headers:
  10. request:
  11. set:
  12. test: "true"
  13. route:
  14. - destination:
  15. host: reviews.prod.svc.cluster.local
  16. subset: v2
  17. weight: 25
  18. - destination:
  19. host: reviews.prod.svc.cluster.local
  20. subset: v1
  21. headers:
  22. response:
  23. remove:
  24. - foo
  25. weight: 75
  1. apiVersion: networking.istio.io/v1beta1
  2. kind: VirtualService
  3. metadata:
  4. name: reviews-route
  5. spec:
  6. hosts:
  7. - reviews.prod.svc.cluster.local
  8. http:
  9. - headers:
  10. request:
  11. set:
  12. test: "true"
  13. route:
  14. - destination:
  15. host: reviews.prod.svc.cluster.local
  16. subset: v2
  17. weight: 25
  18. - destination:
  19. host: reviews.prod.svc.cluster.local
  20. subset: v1
  21. headers:
  22. response:
  23. remove:
  24. - foo
  25. weight: 75
FieldTypeDescriptionRequired
requestHeaderOperations

Header manipulation rules to apply before forwarding a request to the destination service

No
responseHeaderOperations

Header manipulation rules to apply before returning a response to the caller

No

TLSRoute

Describes match conditions and actions for routing unterminated TLS traffic (TLS/HTTPS) The following routing rule forwards unterminated TLS traffic arriving at port 443 of gateway called “mygateway” to internal services in the mesh based on the SNI value.

  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: VirtualService
  3. metadata:
  4. name: bookinfo-sni
  5. spec:
  6. hosts:
  7. - "*.bookinfo.com"
  8. gateways:
  9. - mygateway
  10. tls:
  11. - match:
  12. - port: 443
  13. sniHosts:
  14. - login.bookinfo.com
  15. route:
  16. - destination:
  17. host: login.prod.svc.cluster.local
  18. - match:
  19. - port: 443
  20. sniHosts:
  21. - reviews.bookinfo.com
  22. route:
  23. - destination:
  24. host: reviews.prod.svc.cluster.local
  1. apiVersion: networking.istio.io/v1beta1
  2. kind: VirtualService
  3. metadata:
  4. name: bookinfo-sni
  5. spec:
  6. hosts:
  7. - "*.bookinfo.com"
  8. gateways:
  9. - mygateway
  10. tls:
  11. - match:
  12. - port: 443
  13. sniHosts:
  14. - login.bookinfo.com
  15. route:
  16. - destination:
  17. host: login.prod.svc.cluster.local
  18. - match:
  19. - port: 443
  20. sniHosts:
  21. - reviews.bookinfo.com
  22. route:
  23. - destination:
  24. host: reviews.prod.svc.cluster.local
FieldTypeDescriptionRequired
matchTLSMatchAttributes[]

Match conditions to be satisfied for the rule to be activated. All conditions inside a single match block have AND semantics, while the list of match blocks have OR semantics. The rule is matched if any one of the match blocks succeed.

Yes
routeRouteDestination[]

The destination to which the connection should be forwarded to.

No

TCPRoute

Describes match conditions and actions for routing TCP traffic. The following routing rule forwards traffic arriving at port 27017 for mongo.prod.svc.cluster.local to another Mongo server on port 5555.

  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: VirtualService
  3. metadata:
  4. name: bookinfo-mongo
  5. spec:
  6. hosts:
  7. - mongo.prod.svc.cluster.local
  8. tcp:
  9. - match:
  10. - port: 27017
  11. route:
  12. - destination:
  13. host: mongo.backup.svc.cluster.local
  14. port:
  15. number: 5555
  1. apiVersion: networking.istio.io/v1beta1
  2. kind: VirtualService
  3. metadata:
  4. name: bookinfo-mongo
  5. spec:
  6. hosts:
  7. - mongo.prod.svc.cluster.local
  8. tcp:
  9. - match:
  10. - port: 27017
  11. route:
  12. - destination:
  13. host: mongo.backup.svc.cluster.local
  14. port:
  15. number: 5555
FieldTypeDescriptionRequired
matchL4MatchAttributes[]

Match conditions to be satisfied for the rule to be activated. All conditions inside a single match block have AND semantics, while the list of match blocks have OR semantics. The rule is matched if any one of the match blocks succeed.

No
routeRouteDestination[]

The destination to which the connection should be forwarded to.

No

HTTPMatchRequest

HttpMatchRequest specifies a set of criterion to be met in order for the rule to be applied to the HTTP request. For example, the following restricts the rule to match only requests where the URL path starts with /ratings/v2/ and the request contains a custom end-user header with value jason.

  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: VirtualService
  3. metadata:
  4. name: ratings-route
  5. spec:
  6. hosts:
  7. - ratings.prod.svc.cluster.local
  8. http:
  9. - match:
  10. - headers:
  11. end-user:
  12. exact: jason
  13. uri:
  14. prefix: "/ratings/v2/"
  15. ignoreUriCase: true
  16. route:
  17. - destination:
  18. host: ratings.prod.svc.cluster.local
  1. apiVersion: networking.istio.io/v1beta1
  2. kind: VirtualService
  3. metadata:
  4. name: ratings-route
  5. spec:
  6. hosts:
  7. - ratings.prod.svc.cluster.local
  8. http:
  9. - match:
  10. - headers:
  11. end-user:
  12. exact: jason
  13. uri:
  14. prefix: "/ratings/v2/"
  15. ignoreUriCase: true
  16. route:
  17. - destination:
  18. host: ratings.prod.svc.cluster.local

HTTPMatchRequest CANNOT be empty. Note: No regex string match can be set when delegate VirtualService is specified.

FieldTypeDescriptionRequired
namestring

The name assigned to a match. The match’s name will be concatenated with the parent route’s name and will be logged in the access logs for requests matching this route.

No
uriStringMatch

URI to match values are case-sensitive and formatted as follows:

Note: Case-insensitive matching could be enabled via the ignore_uri_case flag.

No
schemeStringMatch

URI Scheme values are case-sensitive and formatted as follows:

No
methodStringMatch

HTTP Method values are case-sensitive and formatted as follows:

No
authorityStringMatch

HTTP Authority values are case-sensitive and formatted as follows:

No
headersmap<string, StringMatch>

The header keys must be lowercase and use hyphen as the separator, e.g. x-request-id.

Header values are case-sensitive and formatted as follows:

If the value is empty and only the name of header is specfied, presence of the header is checked. Note: The keys uri, scheme, method, and authority will be ignored.

No
portuint32

Specifies the ports on the host that is being addressed. Many services only expose a single port or label ports with the protocols they support, in these cases it is not required to explicitly select the port.

No
sourceLabelsmap<string, string>

One or more labels that constrain the applicability of a rule to source (client) workloads with the given labels. If the VirtualService has a list of gateways specified in the top-level gateways field, it must include the reserved gateway mesh for this field to be applicable.

No
gatewaysstring[]

Names of gateways where the rule should be applied. Gateway names in the top-level gateways field of the VirtualService (if any) are overridden. The gateway match is independent of sourceLabels.

No
queryParamsmap<string, StringMatch>

Query parameters for matching.

Ex:

  • For a query parameter like “?key=true”, the map key would be “key” and the string match could be defined as exact: “true”.

  • For a query parameter like “?key”, the map key would be “key” and the string match could be defined as exact: “”.

  • For a query parameter like “?key=123”, the map key would be “key” and the string match could be defined as regex: “\d+$”. Note that this configuration will only match values like “123” but not “a123” or “123a”.

Note: prefix matching is currently not supported.

No
ignoreUriCasebool

Flag to specify whether the URI matching should be case-insensitive.

Note: The case will be ignored only in the case of exact and prefix URI matches.

No
withoutHeadersmap<string, StringMatch>

withoutHeader has the same syntax with the header, but has opposite meaning. If a header is matched with a matching rule among withoutHeader, the traffic becomes not matched one.

No
sourceNamespacestring

Source namespace constraining the applicability of a rule to workloads in that namespace. If the VirtualService has a list of gateways specified in the top-level gateways field, it must include the reserved gateway mesh for this field to be applicable.

No

HTTPRouteDestination

Each routing rule is associated with one or more service versions (see glossary in beginning of document). Weights associated with the version determine the proportion of traffic it receives. For example, the following rule will route 25% of traffic for the “reviews” service to instances with the “v2” tag and the remaining traffic (i.e., 75%) to “v1”.

  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: VirtualService
  3. metadata:
  4. name: reviews-route
  5. spec:
  6. hosts:
  7. - reviews.prod.svc.cluster.local
  8. http:
  9. - route:
  10. - destination:
  11. host: reviews.prod.svc.cluster.local
  12. subset: v2
  13. weight: 25
  14. - destination:
  15. host: reviews.prod.svc.cluster.local
  16. subset: v1
  17. weight: 75
  1. apiVersion: networking.istio.io/v1beta1
  2. kind: VirtualService
  3. metadata:
  4. name: reviews-route
  5. spec:
  6. hosts:
  7. - reviews.prod.svc.cluster.local
  8. http:
  9. - route:
  10. - destination:
  11. host: reviews.prod.svc.cluster.local
  12. subset: v2
  13. weight: 25
  14. - destination:
  15. host: reviews.prod.svc.cluster.local
  16. subset: v1
  17. weight: 75

And the associated DestinationRule

  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: DestinationRule
  3. metadata:
  4. name: reviews-destination
  5. spec:
  6. host: reviews.prod.svc.cluster.local
  7. subsets:
  8. - name: v1
  9. labels:
  10. version: v1
  11. - name: v2
  12. labels:
  13. version: v2
  1. apiVersion: networking.istio.io/v1beta1
  2. kind: DestinationRule
  3. metadata:
  4. name: reviews-destination
  5. spec:
  6. host: reviews.prod.svc.cluster.local
  7. subsets:
  8. - name: v1
  9. labels:
  10. version: v1
  11. - name: v2
  12. labels:
  13. version: v2

Traffic can also be split across two entirely different services without having to define new subsets. For example, the following rule forwards 25% of traffic to reviews.com to dev.reviews.com

  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: VirtualService
  3. metadata:
  4. name: reviews-route-two-domains
  5. spec:
  6. hosts:
  7. - reviews.com
  8. http:
  9. - route:
  10. - destination:
  11. host: dev.reviews.com
  12. weight: 25
  13. - destination:
  14. host: reviews.com
  15. weight: 75
  1. apiVersion: networking.istio.io/v1beta1
  2. kind: VirtualService
  3. metadata:
  4. name: reviews-route-two-domains
  5. spec:
  6. hosts:
  7. - reviews.com
  8. http:
  9. - route:
  10. - destination:
  11. host: dev.reviews.com
  12. weight: 25
  13. - destination:
  14. host: reviews.com
  15. weight: 75
FieldTypeDescriptionRequired
destinationDestination

Destination uniquely identifies the instances of a service to which the request/connection should be forwarded to.

Yes
weightint32

Weight specifies the relative proportion of traffic to be forwarded to the destination. A destination will receive weight/(sum of all weights) requests. If there is only one destination in a rule, it will receive all traffic. Otherwise, if weight is 0, the destination will not receive any traffic.

No
headersHeaders

Header manipulation rules

No

RouteDestination

L4 routing rule weighted destination.

FieldTypeDescriptionRequired
destinationDestination

Destination uniquely identifies the instances of a service to which the request/connection should be forwarded to.

Yes
weightint32

Weight specifies the relative proportion of traffic to be forwarded to the destination. A destination will receive weight/(sum of all weights) requests. If there is only one destination in a rule, it will receive all traffic. Otherwise, if weight is 0, the destination will not receive any traffic.

No

L4MatchAttributes

L4 connection match attributes. Note that L4 connection matching support is incomplete.

FieldTypeDescriptionRequired
destinationSubnetsstring[]

IPv4 or IPv6 ip addresses of destination with optional subnet. E.g., a.b.c.d/xx form or just a.b.c.d.

No
portuint32

Specifies the port on the host that is being addressed. Many services only expose a single port or label ports with the protocols they support, in these cases it is not required to explicitly select the port.

No
sourceLabelsmap<string, string>

One or more labels that constrain the applicability of a rule to workloads with the given labels. If the VirtualService has a list of gateways specified in the top-level gateways field, it should include the reserved gateway mesh in order for this field to be applicable.

No
gatewaysstring[]

Names of gateways where the rule should be applied. Gateway names in the top-level gateways field of the VirtualService (if any) are overridden. The gateway match is independent of sourceLabels.

No
sourceNamespacestring

Source namespace constraining the applicability of a rule to workloads in that namespace. If the VirtualService has a list of gateways specified in the top-level gateways field, it must include the reserved gateway mesh for this field to be applicable.

No

TLSMatchAttributes

TLS connection match attributes.

FieldTypeDescriptionRequired
sniHostsstring[]

SNI (server name indicator) to match on. Wildcard prefixes can be used in the SNI value, e.g., *.com will match foo.example.com as well as example.com. An SNI value must be a subset (i.e., fall within the domain) of the corresponding virtual serivce’s hosts.

Yes
destinationSubnetsstring[]

IPv4 or IPv6 ip addresses of destination with optional subnet. E.g., a.b.c.d/xx form or just a.b.c.d.

No
portuint32

Specifies the port on the host that is being addressed. Many services only expose a single port or label ports with the protocols they support, in these cases it is not required to explicitly select the port.

No
sourceLabelsmap<string, string>

One or more labels that constrain the applicability of a rule to workloads with the given labels. If the VirtualService has a list of gateways specified in the top-level gateways field, it should include the reserved gateway mesh in order for this field to be applicable.

No
gatewaysstring[]

Names of gateways where the rule should be applied. Gateway names in the top-level gateways field of the VirtualService (if any) are overridden. The gateway match is independent of sourceLabels.

No
sourceNamespacestring

Source namespace constraining the applicability of a rule to workloads in that namespace. If the VirtualService has a list of gateways specified in the top-level gateways field, it must include the reserved gateway mesh for this field to be applicable.

No

HTTPRedirect

HTTPRedirect can be used to send a 301 redirect response to the caller, where the Authority/Host and the URI in the response can be swapped with the specified values. For example, the following rule redirects requests for /v1/getProductRatings API on the ratings service to /v1/bookRatings provided by the bookratings service.

  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: VirtualService
  3. metadata:
  4. name: ratings-route
  5. spec:
  6. hosts:
  7. - ratings.prod.svc.cluster.local
  8. http:
  9. - match:
  10. - uri:
  11. exact: /v1/getProductRatings
  12. redirect:
  13. uri: /v1/bookRatings
  14. authority: newratings.default.svc.cluster.local
  15. ...
  1. apiVersion: networking.istio.io/v1beta1
  2. kind: VirtualService
  3. metadata:
  4. name: ratings-route
  5. spec:
  6. hosts:
  7. - ratings.prod.svc.cluster.local
  8. http:
  9. - match:
  10. - uri:
  11. exact: /v1/getProductRatings
  12. redirect:
  13. uri: /v1/bookRatings
  14. authority: newratings.default.svc.cluster.local
  15. ...
FieldTypeDescriptionRequired
uristring

On a redirect, overwrite the Path portion of the URL with this value. Note that the entire path will be replaced, irrespective of the request URI being matched as an exact path or prefix.

No
authoritystring

On a redirect, overwrite the Authority/Host portion of the URL with this value.

No
portuint32 (oneof)

On a redirect, overwrite the port portion of the URL with this value.

No
derivePortRedirectPortSelection (oneof)

On a redirect, dynamically set the port: FROM_PROTOCOL_DEFAULT: automatically set to 80 for HTTP and 443 for HTTPS. FROM_REQUEST_PORT: automatically use the port of the request.

No
schemestring

On a redirect, overwrite the scheme portion of the URL with this value. For example, http or https. If unset, the original scheme will be used. If derivePort is set to FROM_PROTOCOL_DEFAULT, this will impact the port used as well

No
redirectCodeuint32

On a redirect, Specifies the HTTP status code to use in the redirect response. The default response code is MOVED_PERMANENTLY (301).

No

HTTPRewrite

HTTPRewrite can be used to rewrite specific parts of a HTTP request before forwarding the request to the destination. Rewrite primitive can be used only with HTTPRouteDestination. The following example demonstrates how to rewrite the URL prefix for api call (/ratings) to ratings service before making the actual API call.

  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: VirtualService
  3. metadata:
  4. name: ratings-route
  5. spec:
  6. hosts:
  7. - ratings.prod.svc.cluster.local
  8. http:
  9. - match:
  10. - uri:
  11. prefix: /ratings
  12. rewrite:
  13. uri: /v1/bookRatings
  14. route:
  15. - destination:
  16. host: ratings.prod.svc.cluster.local
  17. subset: v1
  1. apiVersion: networking.istio.io/v1beta1
  2. kind: VirtualService
  3. metadata:
  4. name: ratings-route
  5. spec:
  6. hosts:
  7. - ratings.prod.svc.cluster.local
  8. http:
  9. - match:
  10. - uri:
  11. prefix: /ratings
  12. rewrite:
  13. uri: /v1/bookRatings
  14. route:
  15. - destination:
  16. host: ratings.prod.svc.cluster.local
  17. subset: v1
FieldTypeDescriptionRequired
uristring

rewrite the path (or the prefix) portion of the URI with this value. If the original URI was matched based on prefix, the value provided in this field will replace the corresponding matched prefix.

No
authoritystring

rewrite the Authority/Host header with this value.

No

StringMatch

Describes how to match a given string in HTTP headers. Match is case-sensitive.

FieldTypeDescriptionRequired
exactstring (oneof)

exact string match

No
prefixstring (oneof)

prefix-based match

No
regexstring (oneof)

RE2 style regex-based match (https://github.com/google/re2/wiki/Syntax).

No

HTTPRetry

Describes the retry policy to use when a HTTP request fails. For example, the following rule sets the maximum number of retries to 3 when calling ratings:v1 service, with a 2s timeout per retry attempt. A retry will be attempted if there is a connect-failure, refused_stream or when the upstream server responds with Service Unavailable(503).

  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: VirtualService
  3. metadata:
  4. name: ratings-route
  5. spec:
  6. hosts:
  7. - ratings.prod.svc.cluster.local
  8. http:
  9. - route:
  10. - destination:
  11. host: ratings.prod.svc.cluster.local
  12. subset: v1
  13. retries:
  14. attempts: 3
  15. perTryTimeout: 2s
  16. retryOn: connect-failure,refused-stream,503
  1. apiVersion: networking.istio.io/v1beta1
  2. kind: VirtualService
  3. metadata:
  4. name: ratings-route
  5. spec:
  6. hosts:
  7. - ratings.prod.svc.cluster.local
  8. http:
  9. - route:
  10. - destination:
  11. host: ratings.prod.svc.cluster.local
  12. subset: v1
  13. retries:
  14. attempts: 3
  15. perTryTimeout: 2s
  16. retryOn: gateway-error,connect-failure,refused-stream
FieldTypeDescriptionRequired
attemptsint32

Number of retries to be allowed for a given request. The interval between retries will be determined automatically (25ms+). When request timeout of the HTTP route or per_try_timeout is configured, the actual number of retries attempted also depends on the specified request timeout and per_try_timeout values.

Yes
perTryTimeoutDuration

Timeout per attempt for a given request, including the initial call and any retries. Format: 1h/1m/1s/1ms. MUST BE >=1ms. Default is same value as request timeout of the HTTP route, which means no timeout.

No
retryOnstring

Specifies the conditions under which retry takes place. One or more policies can be specified using a ‘,’ delimited list. If retry_on specifies a valid HTTP status, it will be added to retriable_status_codes retry policy. See the retry policies and gRPC retry policies for more details.

No
retryRemoteLocalitiesBoolValue

Flag to specify whether the retries should retry to other localities. See the retry plugin configuration for more details.

No

CorsPolicy

Describes the Cross-Origin Resource Sharing (CORS) policy, for a given service. Refer to CORS for further details about cross origin resource sharing. For example, the following rule restricts cross origin requests to those originating from example.com domain using HTTP POST/GET, and sets the Access-Control-Allow-Credentials header to false. In addition, it only exposes X-Foo-bar header and sets an expiry period of 1 day.

  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: VirtualService
  3. metadata:
  4. name: ratings-route
  5. spec:
  6. hosts:
  7. - ratings.prod.svc.cluster.local
  8. http:
  9. - route:
  10. - destination:
  11. host: ratings.prod.svc.cluster.local
  12. subset: v1
  13. corsPolicy:
  14. allowOrigins:
  15. - exact: https://example.com
  16. allowMethods:
  17. - POST
  18. - GET
  19. allowCredentials: false
  20. allowHeaders:
  21. - X-Foo-Bar
  22. maxAge: "24h"
  1. apiVersion: networking.istio.io/v1beta1
  2. kind: VirtualService
  3. metadata:
  4. name: ratings-route
  5. spec:
  6. hosts:
  7. - ratings.prod.svc.cluster.local
  8. http:
  9. - route:
  10. - destination:
  11. host: ratings.prod.svc.cluster.local
  12. subset: v1
  13. corsPolicy:
  14. allowOrigins:
  15. - exact: https://example.com
  16. allowMethods:
  17. - POST
  18. - GET
  19. allowCredentials: false
  20. allowHeaders:
  21. - X-Foo-Bar
  22. maxAge: "24h"
FieldTypeDescriptionRequired
allowOriginsStringMatch[]

String patterns that match allowed origins. An origin is allowed if any of the string matchers match. If a match is found, then the outgoing Access-Control-Allow-Origin would be set to the origin as provided by the client.

No
allowMethodsstring[]

List of HTTP methods allowed to access the resource. The content will be serialized into the Access-Control-Allow-Methods header.

No
allowHeadersstring[]

List of HTTP headers that can be used when requesting the resource. Serialized to Access-Control-Allow-Headers header.

No
exposeHeadersstring[]

A list of HTTP headers that the browsers are allowed to access. Serialized into Access-Control-Expose-Headers header.

No
maxAgeDuration

Specifies how long the results of a preflight request can be cached. Translates to the Access-Control-Max-Age header.

No
allowCredentialsBoolValue

Indicates whether the caller is allowed to send the actual request (not the preflight) using credentials. Translates to Access-Control-Allow-Credentials header.

No

HTTPFaultInjection

HTTPFaultInjection can be used to specify one or more faults to inject while forwarding HTTP requests to the destination specified in a route. Fault specification is part of a VirtualService rule. Faults include aborting the Http request from downstream service, and/or delaying proxying of requests. A fault rule MUST HAVE delay or abort or both.

Note: Delay and abort faults are independent of one another, even if both are specified simultaneously.

FieldTypeDescriptionRequired
delayDelay

Delay requests before forwarding, emulating various failures such as network issues, overloaded upstream service, etc.

No
abortAbort

Abort Http request attempts and return error codes back to downstream service, giving the impression that the upstream service is faulty.

No

PortSelector

PortSelector specifies the number of a port to be used for matching or selection for final routing.

FieldTypeDescriptionRequired
numberuint32

Valid port number

No

Percent

Percent specifies a percentage in the range of [0.0, 100.0].

FieldTypeDescriptionRequired
valuedoubleNo

Headers.HeaderOperations

HeaderOperations Describes the header manipulations to apply

FieldTypeDescriptionRequired
setmap<string, string>

Overwrite the headers specified by key with the given values

No
addmap<string, string>

Append the given values to the headers specified by keys (will create a comma-separated list of values)

No
removestring[]

Remove the specified headers

No

HTTPFaultInjection.Delay

Delay specification is used to inject latency into the request forwarding path. The following example will introduce a 5 second delay in 1 out of every 1000 requests to the “v1” version of the “reviews” service from all pods with label env: prod

  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: VirtualService
  3. metadata:
  4. name: reviews-route
  5. spec:
  6. hosts:
  7. - reviews.prod.svc.cluster.local
  8. http:
  9. - match:
  10. - sourceLabels:
  11. env: prod
  12. route:
  13. - destination:
  14. host: reviews.prod.svc.cluster.local
  15. subset: v1
  16. fault:
  17. delay:
  18. percentage:
  19. value: 0.1
  20. fixedDelay: 5s
  1. apiVersion: networking.istio.io/v1beta1
  2. kind: VirtualService
  3. metadata:
  4. name: reviews-route
  5. spec:
  6. hosts:
  7. - reviews.prod.svc.cluster.local
  8. http:
  9. - match:
  10. - sourceLabels:
  11. env: prod
  12. route:
  13. - destination:
  14. host: reviews.prod.svc.cluster.local
  15. subset: v1
  16. fault:
  17. delay:
  18. percentage:
  19. value: 0.1
  20. fixedDelay: 5s

The fixedDelay field is used to indicate the amount of delay in seconds. The optional percentage field can be used to only delay a certain percentage of requests. If left unspecified, all request will be delayed.

FieldTypeDescriptionRequired
fixedDelayDuration (oneof)

Add a fixed delay before forwarding the request. Format: 1h/1m/1s/1ms. MUST be >=1ms.

Yes
percentagePercent

Percentage of requests on which the delay will be injected.

No
percentint32

Percentage of requests on which the delay will be injected (0-100). Use of integer percent value is deprecated. Use the double percentage field instead.

No

HTTPFaultInjection.Abort

Abort specification is used to prematurely abort a request with a pre-specified error code. The following example will return an HTTP 400 error code for 1 out of every 1000 requests to the “ratings” service “v1”.

  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: VirtualService
  3. metadata:
  4. name: ratings-route
  5. spec:
  6. hosts:
  7. - ratings.prod.svc.cluster.local
  8. http:
  9. - route:
  10. - destination:
  11. host: ratings.prod.svc.cluster.local
  12. subset: v1
  13. fault:
  14. abort:
  15. percentage:
  16. value: 0.1
  17. httpStatus: 400
  1. apiVersion: networking.istio.io/v1beta1
  2. kind: VirtualService
  3. metadata:
  4. name: ratings-route
  5. spec:
  6. hosts:
  7. - ratings.prod.svc.cluster.local
  8. http:
  9. - route:
  10. - destination:
  11. host: ratings.prod.svc.cluster.local
  12. subset: v1
  13. fault:
  14. abort:
  15. percentage:
  16. value: 0.1
  17. httpStatus: 400

The httpStatus field is used to indicate the HTTP status code to return to the caller. The optional percentage field can be used to only abort a certain percentage of requests. If not specified, all requests are aborted.

FieldTypeDescriptionRequired
httpStatusint32 (oneof)

HTTP status code to use to abort the Http request.

Yes
percentagePercent

Percentage of requests to be aborted with the error code provided.

No

google.protobuf.UInt32Value

Wrapper message for uint32.

The JSON representation for UInt32Value is JSON number.

FieldTypeDescriptionRequired
valueuint32

The uint32 value.

No

HTTPRedirect.RedirectPortSelection

NameDescription
FROM_PROTOCOL_DEFAULT
FROM_REQUEST_PORT