Skip to main content

Traffic Splitting

Traffic splitting is a service mesh capability that routes a set percentage of requests to different versions of a service at the same time. It supports canary releases, A/B tests, and gradual migrations without changing replica counts.

Why use it

Splitting by replica count ties traffic share to pod counts, so 5 percent needs about 20 pods. A mesh splits at the routing layer, so a single replica of v2 can still receive an exact 5 percent, and you can change the weights without touching your Deployments.

flowchart TD R["Incoming requests"] --> V{"VirtualService
weights"} V -->|"95 percent"| A["v1 subset"] V -->|"5 percent"| B["v2 subset"] D["DestinationRule
defines subsets"] -.->|"by pod label"| A D -.->|"by pod label"| B classDef start fill:#475569,color:#ffffff classDef route fill:#FFEDD5,color:#1E293B classDef rule fill:#8B5CF6,color:#ffffff classDef sub fill:#D1FAE5,color:#1E293B class R start class V route class D rule class A,B sub

Istio example

YAML
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
name: restaurant-service
namespace: production
spec:
hosts:
- restaurant-service
http:
- route:
- destination:
host: restaurant-service
subset: v1
weight: 95
- destination:
host: restaurant-service
subset: v2
weight: 5
YAML
apiVersion: networking.istio.io/v1
kind: DestinationRule
metadata:
name: restaurant-service
namespace: production
spec:
host: restaurant-service
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2

Header-based routing for testers

YAML
http:
- match:
- headers:
x-canary:
exact: "true"
route:
- destination:
host: restaurant-service
subset: v2
- route:
- destination:
host: restaurant-service
subset: v1

Rollout and rollback

  • Step weights up gradually, such as 5, 25, 50, 100, while watching error rate and p99 latency per version.
  • To roll back, set v2 weight to 0 and v1 to 100.
Remember

Both resources are required. Weights without defined subsets cause 503 errors.

Tip

Automate progression and rollback with Flagger or Argo Rollouts driven by per-version metrics.

Common Mistake

Reading aggregated dashboards. A canary can double its error rate on 5 percent of traffic and stay invisible unless metrics are broken down by version.

Frequently Asked Questions

How does mesh splitting differ from scaling replicas?

Replica scaling gives a rough share tied to pod counts. A mesh sets exact percentages at the request-routing layer regardless of replicas.

Can I split by something other than percentage?

Yes. You can match headers, paths, query parameters, or source labels, which lets testers reach a new version while customers stay on the stable one.

Does the Kubernetes Gateway API do this too?

Yes. HTTPRoute supports weighted backends, so splitting is available without a mesh in many ingress and gateway implementations.

Found a mistake, an outdated step or a broken link?