CKA · 20 November 2026 · 4 min read

Blue/green deployments with the Gateway API

Weights are built into the Gateway API: an HTTPRoute sends blue 100 and green 0, a header rule lets you test green, and swapping the weights releases or rolls back. With YAML, kubectl and the status to check.

The Gateway API makes blue/green a standard part of routing: an HTTPRoute lists both Services as backends with a weight each, so blue at 100 and green at 0 sends everyone to blue. A second rule that matches a header sends only your test requests to green. To release, swap the weights to 0 and 100; to roll back, swap them again. Set 90 and 10 instead and the same route is a canary. It works the same on any controller that implements the Gateway API, and it is on the CKA curriculum.

TL;DR

  • A Gateway (the listener, owned by the platform) and an HTTPRoute (your routing, owned by the app).
  • Backends with weights: shop-blue weight 100, shop-green weight 0.
  • Test green first with a header match: x-version: green goes to green only.
  • Switch: patch the weights to 0 and 100. Roll back: patch them back. Canary: anything in between.
  • Check kubectl get httproute shop -o yaml: Accepted and ResolvedRefs must be True.
  • Exam: the CKA's Services and Networking includes using the Gateway API to manage ingress traffic; blue/green is in the CKAD's Application Deployment.

The whole pattern in one picture

Blue/green with the Gateway API: users reach Gateway shop-gateway, which uses HTTPRoute policy to send traffic by weight to Services shop-blue (100) and shop-green (0). The Services select Pod endpoints; requests with the header x-version: green go to green; swapping the weights releases green.

Want to change it for your own setup? Open this diagram in archhy, our sister product for architecture diagrams, and press Make a copy in archhy: it opens as your own copy, ready to edit.

Why the Gateway API

An Ingress rule sends a host to one Service, so weights need controller-specific extras (see part 2). The Gateway API, the successor to Ingress in Kubernetes, has weights, header matching and status built in, and splits the work: whoever runs the cluster owns the Gateway, and each team owns its routes. It is also the Kubernetes project's recommended path now that ingress-nginx is retired.

Using ingress-nginx? It was retired in March 2026 and gets no more fixes. Read ingress-nginx is retired: your options: the Gateway API, another controller that reads its annotations, or your cloud's option, with the tool that converts your Ingress resources.

Step 1: blue, green and their Services

As in part 2: Deployments shop-blue (nginx:1.26, version: blue) and shop-green (nginx:1.27, version: green), each with its own Service, shop-blue and shop-green, on port 80.

Step 2: the Gateway

Your cluster needs a Gateway API controller and its GatewayClass (kubectl get gatewayclass). On k3s that can be Traefik, whose plain-HTTP entry point listens on port 8000 inside its Pod:

YAML
apiVersion: gateway.networking.k8s.io/v1kind: Gatewaymetadata:  name: shop-gatewayspec:  gatewayClassName: traefik  listeners:  - name: web    protocol: HTTP    port: 8000

The listener port must match what your controller listens on; Envoy Gateway, Istio and others usually take 80. Check that the Gateway reports Programmed: kubectl get gateway shop-gateway.

Step 3: the route, with weights and a test rule

YAML
apiVersion: gateway.networking.k8s.io/v1kind: HTTPRoutemetadata:  name: shopspec:  parentRefs:  - name: shop-gateway  hostnames:  - shop.example.com  rules:  # rules[0]: only requests carrying x-version: green reach green  - matches:    - headers:      - name: x-version        value: green    backendRefs:    - name: shop-green      port: 80  # rules[1]: everyone else, by weight  - backendRefs:    - name: shop-blue      port: 80      weight: 100    - name: shop-green      port: 80      weight: 0

A weight of 0 is allowed and sends nothing. The header rule is more specific, so it wins for requests that carry the header. Test both; nginx's Server header shows the version (1.26 is blue, 1.27 is green):

Shell
kubectl apply -f gateway.yaml -f route.yamlkubectl get httproute shop -o jsonpath='{.status.parents[0].conditions[*].type}'curl -sI -H 'Host: shop.example.com' http://<gateway-address>/ | grep -i '^server'curl -sI -H 'Host: shop.example.com' -H 'x-version: green' http://<gateway-address>/ | grep -i '^server'

Step 4: switch, and switch back

When green is good, swap the weights in the second rule:

Shell
kubectl patch httproute shop --type=json -p '[  {"op":"replace","path":"/spec/rules/1/backendRefs/0/weight","value":0},  {"op":"replace","path":"/spec/rules/1/backendRefs/1/weight","value":100}]'

To roll back, set them to 100 and 0 again. For a gradual release, step through 90/10, 50/50 and 0/100 and watch your error rate at each step: that is a canary, from the same route. Once green has carried all traffic for long enough, remove blue from the route and scale its Deployment to zero.

Things that catch people out

  • The route is not attached. If parentRefs names the wrong Gateway, or the Gateway's listener does not allow routes from your namespace, the route's Accepted condition is False and no traffic arrives. Read the status before testing.
  • ResolvedRefs is False. A backend Service name or port is wrong, or the Service is in another namespace without a ReferenceGrant.
  • The listener port. It is the port your controller's proxy listens on, which is not always 80 (Traefik's is 8000).
  • Weights are proportions, not percentages: 1 and 3 send a quarter to the first. Using numbers that add up to 100 keeps it readable.
  • Keep-alive connections stay where they are until they reconnect, as with any switch.

The blue/green series

  1. Blue/green with a Service selector: the pattern, and the version the exam asks for.
  2. Blue/green with an Ingress: switch the backend at the edge; weights with Traefik.
  3. Blue/green with the Gateway API (this article): standard weights in an HTTPRoute, and a header to test green.
  4. Blue/green with Istio: subsets, weights, mirroring live traffic to green.

Keep going

The CKA's Ingress and network policy module has a guided lab, Route traffic with the Gateway API, that builds a Gateway and a weighted HTTPRoute with Traefik on a real kubeadm cluster.

More from the blog