Istio Traffic Management: VirtualServices, DestinationRules, and Gateways
The five Istio traffic management resources
Once Istio’s Control Plane is running and proxies form the Data Plane, operators control cluster traffic using five Kubernetes Custom Resources (PDF p. 34 / printed slide 36):
| Resource | Role in plain English | Scope / where it acts |
|---|---|---|
VirtualService | Defines an ordered list of routing rules telling proxies where requests for a service should go (e.g., by HTTP header or percentage weights) | Mesh routing rules |
DestinationRule | Defines policies applied after VirtualService routing selects a destination—such as load balancing strategies, circuit breaking settings, TLS, and defining version subsets | Post-routing target policies |
Gateway | Manages inbound and outbound traffic at the edge of the mesh (North-South), specifying exposed ports, hostnames, and TLS certificates | Standalone edge Envoy proxies (not app sidecars) |
ServiceEntry | Registers external dependencies (services living outside the Kubernetes cluster, such as third-party APIs) inside Istio’s service registry | Egress / external dependencies |
Sidecar | Configures the scope of Envoy proxies—limiting which services/namespaces a proxy knows about (e.g., namespace isolation and reduced Envoy config memory) | Per-namespace/workload proxy scope |
Common confusion:
VirtualServicevs.DestinationRule
VirtualServiceanswers “Which destination (e.g.,v2vs.v3) gets this request?”DestinationRuleanswers “Once a destination has been chosen, how should Envoy talk to it?” (e.g., least-request load balancing, circuit breaker thresholds, or mappingsubset: v2to Pod labelversion: v2).
Worked example 1: VirtualService (PDF p. 35 / printed slide 37)
A VirtualService builds on basic service discovery to route requests based on HTTP attributes, fallback chains, or percentage weights:
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
name: reviews
spec:
hosts:
- reviews
http:
- match:
- headers:
end-user:
exact: jason
route:
- destination:
host: reviews
subset: v2
- route:
- destination:
host: reviews
subset: v3Line-by-line trace
hosts: - reviews: The user-addressable destination (here, the Kubernetes Service namedreviews) that these routing rules govern.- First
httprule (match): Evaluated first becausehttp:rules are an ordered list. It checks whether the incoming HTTP request carries the exact headerend-user: jason. - Matched
route: Requests fromjasonare sent tohost: reviews,subset: v2(and would fall back tov3ifv2is unavailable, or could split traffic usingweightvalues for canary/A-B rollouts). - Second
httprule (default fallback): Has nomatchblock, so every request not matchingend-user: jasonfalls through and is routed tohost: reviews,subset: v3.
Worked example 2: Gateway (PDF p. 36 / printed slide 38)
Whereas sidecar proxies sit beside application containers for internal East-West traffic, a Gateway configures standalone Envoy proxies running at the edge of the mesh to control which external traffic can enter or leave:
apiVersion: networking.istio.io/v1
kind: Gateway
metadata:
name: ext-host-gwy
spec:
selector:
app: my-gateway-controller
servers:
- port:
number: 443
name: https
protocol: HTTPS
hosts:
- ext-host.example.com
tls:
mode: SIMPLE
credentialName: ext-host-certLine-by-line trace
selector: app: my-gateway-controller: Selects the standalone edge Envoy proxy Pods carrying this label—not application sidecar proxies.servers->port: Opens port443forHTTPStraffic.hosts: - ext-host.example.com: Permits inbound traffic addressed toext-host.example.com.tls: Configures standard (SIMPLE) TLS termination using the Kubernetes Secret/credential namedext-host-cert.
How
GatewayandVirtualServicepair at the edge
Gatewayopens the L4/L6 door at the edge (port, host, TLS certificate), while a boundVirtualServicespecifies how traffic arriving through that gateway is routed to internal services inside the mesh.
Retrieval
- Using the
reviewsVirtualServiceYAML above, trace where two requests go: (a) a request with headerend-user: jason, and (b) a request with headerend-user: alice. Why does rule order matter?
Request (a) matches the firsthttprule and goes toreviewssubset: v2. Request (b) fails the firstmatchand falls through to the second unconditional rule, going toreviewssubset: v3. Rule order matters because Istio evaluateshttprules top-to-bottom and applies the first match—putting the catch-all rule first would shadow thejasonrule. - Distinguish
VirtualService,DestinationRule, andServiceEntrywhen configuring an app that splits traffic 90/10 betweenbilling-v1andbilling-v2using least-request load balancing, and also callsapi.stripe.com.VirtualServicedefines the 90% / 10% routing split betweenv1andv2.DestinationRuledefines the least-request load balancing policy (and thev1/v2subsets) applied after routing.ServiceEntryregisters the external dependencyapi.stripe.comin Istio’s mesh registry so egress rules and telemetry can govern it.
- Why does the
ext-host-gwyGatewayresource specifyselector: app: my-gateway-controllerinstead of targeting your application Pods directly?
BecauseGatewayconfigurations apply to standalone Envoy proxies deployed at the edge of the mesh (North-South entry/exit points), rather than the sidecar Envoy proxies running alongside individual microservice workloads.
Source: Lecture 13 - Service Mesh and Istio, PDF pages 34–36 (printed slides 36–38).