Kuberneteskubernetescanaryistioprogressive-deliveryproduction-ready
Canary Deployment with Traffic Splitting
Progressive canary deployment using Kubernetes with Istio traffic splitting, automated analysis, and rollback triggers.
title: "Canary Deployment with Traffic Splitting" description: "Progressive canary deployment using Kubernetes with Istio traffic splitting, automated analysis, and rollback triggers." category: "Kubernetes" language: "yaml" tags: ["kubernetes", "canary", "istio", "progressive-delivery", "production-ready"] createdAt: "2025-04-01" updatedAt: "2025-04-15"
Overview
Canary deployment gradually shifts traffic to a new version while monitoring for errors. Istio's VirtualService enables precise traffic splitting (5% to canary) and header-based routing for targeted testing before full rollout.
Code
# Increase canary traffic to 25%
kubectl patch virtualservice api -n production --type merge \
-p '{"spec":{"http":[{"route":[{"destination":{"host":"api","subset":"stable"},"weight":75},{"destination":{"host":"api","subset":"canary"},"weight":25}]}]}}'Notes
- Start with 5% canary traffic, then increase to 25%, 50%, 100% as confidence grows
- Header-based routing (
x-canary: true) lets QA test the canary explicitly - Monitor error rates, latency p99, and saturation for the canary subset specifically
- Automated rollback: if canary error rate exceeds stable by 2x, route all traffic to stable
- Canary requires fewer resources than blue-green (only 1 extra pod vs. full duplicate)