Kubernetes cookbook · Advanced

Send a percentage of traffic to a new version with the Gateway API

Release a new version to 10% of users first, then increase.

Create a free account to save this page, take notes and track your progress. Sign in

Approach

Run the stable and canary versions as separate Deployments and Services, and split traffic with weighted backendRefs in an HTTPRoute. Change weights step by step while watching error rates.

Solution

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata: {name: shop}
spec:
  parentRefs: [{name: public-gateway, namespace: infra}]
  hostnames: [shop.example.com]
  rules:
    - backendRefs:
        - {name: web-stable, port: 80, weight: 90}
        - {name: web-canary, port: 80, weight: 10}

Pitfalls

  • Sticky sessions or caches that mix versions in one user journey unexpectedly.
  • Database changes that the stable version can't handle.

Variations

  • Header-based routing (matches: headers) to send internal users to the canary first.
  • Argo Rollouts or Flagger to automate weights based on metrics.

Further reading: Gateway API: traffic splitting

Reference: https://gateway-api.sigs.k8s.io/guides/traffic-splitting/

More Kubernetes recipes

Was this page helpful?