Course contentsShow
← Docker, Kubernetes & CI/CD
Lesson 396 of 8026. Kubernetes Traffic and ScalingFree lesson

Managing Traffic Splitting for Canary Deployments

You will shift incremental percentages of traffic between service versions to perform safe canary releases without downtime.

In this lesson, you will learn how to orchestrate granular traffic shifts between service versions using Istio to ensure safe, zero-downtime canary releases.

While basic Kubernetes Ingress allows for simple host or path-based routing, it lacks the surgical precision required to route a specific percentage of traffic to a new version. By leveraging the Istio VirtualService resource, we can decouple the service deployment from the routing logic, allowing us to shift small increments of live production traffic to a new "Canary" version before a full rollout.

Configuring the Traffic Split

To perform a canary release, you define a VirtualService that references your DestinationRule. Instead of sending all requests to a single subset, you distribute the weight across two defined subsets: v1 (the stable version) and v2 (the new candidate).

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: my-app-route
spec:
  hosts:
    - my-app
  http:
    - route:
      - destination:
          host: my-app
          subset: v1
        weight: 90
      - destination:
          host: my-app
          subset: v2
        weight: 10

Why This Matters

In this example, 90% of your users continue to experience the stable environment, while 10% are routed to the new version. This "Canary" approach allows you to monitor logs, latency, and error rates for the new version in real-time. If the Canary deployment shows performance degradation or increased 5xx errors, you can immediately revert the traffic by updating the weight to 100 for v1.

Because Istio handles this routing at the sidecar proxy level (Envoy) rather than relying on standard Kubernetes Service load balancing, the transition is seamless and connection-aware. This eliminates the "connection flapping" often seen when relying solely on replica scaling for traffic distribution. By incrementally shifting traffic—from 10% to 50% and eventually 100%—you minimize the blast radius of any potential bugs while gaining confidence in your deployment.

Key Takeaway: Managing traffic splits via Istio VirtualServices allows you to safely validate new code against live traffic by precisely controlling the percentage of requests routed to your Canary version.