Skip to content
Tutorials Center
My learning

Topics

Lesson 11 of 36 ยท Traffic Management

Weighted Routing and Canary Releases

Shift traffic between versions by percentage with Istio, run a canary rollout step by step, and learn how to roll back safely, with a rollout simulator.

Deploying a new version to every user at once is a gamble. A canary release sends a small share of traffic to the new version, watches its health, and increases the share only if it behaves. With Istio the split is independent of how many pods each version has.

The routing resource

Assume the DestinationRule from Virtual Services and Destination Rules defines subsets v1 and v2 for catalog. A 90/10 split:

YAML
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
  name: catalog
  namespace: shop
spec:
  hosts:
    - catalog
  http:
    - route:
        - destination:
            host: catalog
            subset: v1
          weight: 90
        - destination:
            host: catalog
            subset: v2
          weight: 10

Each request is assigned independently by weighted random choice, so over a short window the split is approximate; over thousands of requests it converges. Applying a new weight is just a kubectl apply: istiod pushes it, and no pod restarts.

A typical canary rollout

Deploy v2 Zero traffic at first.
5 to 10 percent Watch errors and latency.
50 percent Check capacity too.
100 percent Retire v1 later.

Roll back by setting v2 to 0.

1 / 2

A rollout step by step

  1. Deploy v2 as its own Deployment with version: v2. It receives nothing yet because the VirtualService sends 100% to v1.
  2. Verify it with a targeted request (a header match, see Header and Path-Based Routing) before any real user sees it.
  3. Shift 5 to 10%. Watch the error rate and p99 latency of v2 against v1. Istio's metrics carry a destination_version label for this comparison.
  4. Increase in steps (25, 50, 100) with pauses between.
  5. Roll back instantly by restoring 90/10 -> 100/0. No redeploy needed.
  6. Clean up: once v2 is at 100%, delete v1 and simplify the VirtualService.

Make sure v2 has enough replicas for the traffic you give it. A 50% weight on a single pod will overload it even though the percentage is "safe". This is the second thing a mesh does not do for you: weights are not capacity planning. Autoscaling per version helps.

Automating the rollout

Doing the steps by hand teaches you the mechanism. Production teams usually automate them with a progressive-delivery controller (for example Flagger or Argo Rollouts) that edits these weights, queries Prometheus, and rolls back on its own. Istio provides the weighted routing; the controller provides the decision loop.

Weights across more than two versions

You may list any number of destinations; weights must be integers that normally add up to 100. A destination with weight 0 is allowed and keeps the route in place for an instant switch. A single destination needs no weight.

A rollout simulator

This stand-in simulates a weighted split and a promote-or-rollback decision from error rates. Randomness is seeded so the output is stable. It illustrates the decision logic that tools like Flagger automate; it is not Istio.

Python Stand-in: weighted split of requests

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Python Stand-in: automatic promote or roll back

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

  • Blue/green: switch 100% from v1 to v2 at once, keeping v1 as an instant fallback.
  • Dark launch: v2 receives mirrored copies of traffic, but its responses are discarded. See Traffic Mirroring and Fault Injection.
  • Targeted rollout: only users with a header, cookie or internal IP see v2.
  • A/B testing: split by a user attribute, not randomly, so one user always sees one variant (use a consistent-hash load balancer or a header match).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why can Istio send exactly 5% of traffic to a new version when Kubernetes alone cannot?

    The VirtualService weight is enforced in Envoy; Kubernetes Services split roughly by endpoint count.
  2. 2. How do you roll back a canary quickly?

    Config is pushed to proxies within seconds; no pods need to change.
  3. 3. What is a risk of sending 50% of traffic to a single v2 pod?

    Weights do not provision capacity; size and scale each version for its share.
  4. 4. Which describes a dark launch?

    Traffic mirroring lets you test a new version with real requests without user impact.

Summary

  • Weighted routes in a VirtualService split traffic by percentage, independent of replicas.
  • A canary rolls out in small steps while you compare errors and latency per version.
  • Rollback is a config change, effective within seconds.
  • Capacity per version still matters; controllers like Flagger automate the loop.
  • Related patterns: blue/green, dark launch, targeted rollout and A/B tests.

Next: Header and Path-Based Routing