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):

ResourceRole in plain EnglishScope / where it acts
VirtualServiceDefines 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
DestinationRuleDefines policies applied after VirtualService routing selects a destination—such as load balancing strategies, circuit breaking settings, TLS, and defining version subsetsPost-routing target policies
GatewayManages inbound and outbound traffic at the edge of the mesh (North-South), specifying exposed ports, hostnames, and TLS certificatesStandalone edge Envoy proxies (not app sidecars)
ServiceEntryRegisters external dependencies (services living outside the Kubernetes cluster, such as third-party APIs) inside Istio’s service registryEgress / external dependencies
SidecarConfigures 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: VirtualService vs. DestinationRule

  • VirtualService answers “Which destination (e.g., v2 vs. v3) gets this request?”
  • DestinationRule answers “Once a destination has been chosen, how should Envoy talk to it?” (e.g., least-request load balancing, circuit breaker thresholds, or mapping subset: v2 to Pod label version: 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: v3

Line-by-line trace

  1. hosts: - reviews: The user-addressable destination (here, the Kubernetes Service named reviews) that these routing rules govern.
  2. First http rule (match): Evaluated first because http: rules are an ordered list. It checks whether the incoming HTTP request carries the exact header end-user: jason.
  3. Matched route: Requests from jason are sent to host: reviews, subset: v2 (and would fall back to v3 if v2 is unavailable, or could split traffic using weight values for canary/A-B rollouts).
  4. Second http rule (default fallback): Has no match block, so every request not matching end-user: jason falls through and is routed to host: 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-cert

Line-by-line trace

  1. selector: app: my-gateway-controller: Selects the standalone edge Envoy proxy Pods carrying this label—not application sidecar proxies.
  2. servers -> port: Opens port 443 for HTTPS traffic.
  3. hosts: - ext-host.example.com: Permits inbound traffic addressed to ext-host.example.com.
  4. tls: Configures standard (SIMPLE) TLS termination using the Kubernetes Secret/credential named ext-host-cert.

How Gateway and VirtualService pair at the edge

Gateway opens the L4/L6 door at the edge (port, host, TLS certificate), while a bound VirtualService specifies how traffic arriving through that gateway is routed to internal services inside the mesh.

Retrieval

  1. Using the reviews VirtualService YAML above, trace where two requests go: (a) a request with header end-user: jason, and (b) a request with header end-user: alice. Why does rule order matter?
    Request (a) matches the first http rule and goes to reviews subset: v2. Request (b) fails the first match and falls through to the second unconditional rule, going to reviews subset: v3. Rule order matters because Istio evaluates http rules top-to-bottom and applies the first match—putting the catch-all rule first would shadow the jason rule.
  2. Distinguish VirtualService, DestinationRule, and ServiceEntry when configuring an app that splits traffic 90/10 between billing-v1 and billing-v2 using least-request load balancing, and also calls api.stripe.com.
    • VirtualService defines the 90% / 10% routing split between v1 and v2.
    • DestinationRule defines the least-request load balancing policy (and the v1/v2 subsets) applied after routing.
    • ServiceEntry registers the external dependency api.stripe.com in Istio’s mesh registry so egress rules and telemetry can govern it.
  3. Why does the ext-host-gwy Gateway resource specify selector: app: my-gateway-controller instead of targeting your application Pods directly?
    Because Gateway configurations 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).