Blue-Green and Canary Deployments with Gateway API

Kubernetes Gateway API provides native, granular traffic-splitting and header-based routing via the HTTPRoute resource.
Unlike legacy Ingress controllers (which often required proprietary annotations or service-mesh sidecars for traffic weighting), Gateway API allows defining percentage-based Canary/Blue-Green deployments and Header-based test routing directly in the standard API specification.
📺 Video Walkthrough
Traffic Splitting Architecture
graph TD
Client["Client Request"] --> GW["Gateway (external-gateway)"]
GW --> HR["HTTPRoute (myapp-route-http)"]
HR -- "80% Traffic (Weight: 80)" --> Blue["Service V1 (Blue - Stable)"]
HR -- "20% Traffic (Weight: 20)" --> Green["Service V2 (Green - Canary)"]
HR -- "Header: traffic=test" --> Red["Service V3 (QA / Preview)"]
HTTPRoute Configuration
bluegreen-httproute.yaml
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: myapp-route-http
namespace: default
spec:
parentRefs:
- group: gateway.networking.k8s.io
kind: Gateway
name: external-gateway
namespace: gateway
hostnames:
- bluegreen.vettom.online
rules:
# 1. Header-based routing rule (e.g. QA / Internal testers)
- matches:
- headers:
- name: traffic
type: Exact
value: test
backendRefs:
- name: myapp-v3-bluegreen
port: 8080
weight: 1
# 2. Percentage-based weighted traffic split (Canary / Blue-Green)
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: myapp-v1-bluegreen
port: 8080
weight: 80 # 80% to Blue (V1)
- name: myapp-v2-bluegreen
port: 8080
weight: 20 # 20% to Green (V2)
Executing the Cutover
- Canary Phase: Deploy V2 and send 20% of production traffic to monitor error rates and latency.
- Full Cutover: Update the weights (
myapp-v1-bluegreen: 0,myapp-v2-bluegreen: 100) to seamlessly transition 100% of live traffic without downtime. - Rollback: If anomalies are detected in V2, instantly revert weights (
V1: 100,V2: 0).