FIELD NOTESKUBERNETES · DEVOPS

Blue/green with the Gateway API: weights, not tricks

An HTTPRoute lists both versions with a weight each: blue 100, green 0. Swap the numbers to release, test green with a header, and get a canary from the same route. Why the Gateway API is where to start now.

By Space Dog Vin2 min readPublished
ON THIS PAGE
Blue/green with the Gateway API: users reach Gateway shop-gateway; HTTPRoute shop sends weight 100 to Service shop-blue and 0 to shop-green, and the header x-version: green to green. Drawn in archhy.

The Gateway API makes blue/green a field rather than a trick: an HTTPRoute lists both versions as backends with a weight each, so blue 100 and green 0 sends everyone to blue, and swapping the numbers is the release. A header rule sends only your test requests to green first. Set 90 and 10 instead and the same route is a canary. It is standard Kubernetes, so it means the same thing on every controller that implements it.

Based on the article from Gazeek, our sister site for hands-on CKA and CKAD labs: Blue/green deployments with the Gateway API. The Gateway, the HTTPRoute and the patch are there in full.

Two objects, two owners#

  • A Gateway is the listener: a class (which controller runs it) and a port. Whoever runs the platform owns it.
  • An HTTPRoute attaches to the Gateway and does the routing: hostnames, matches, and backends with weights. Each team owns its own.

That split is the real improvement over Ingress, more than the weights. The platform team can change the front door without touching anyone's routes, and a team can release without asking for an annotation it is not allowed to set.

Blue/green, in route terms#

  • Live: backends shop-blue weight 100 and shop-green weight 0. A weight of 0 is allowed and sends nothing.
  • Test: a first rule matching the header x-version: green sends just those requests to green.
  • Release: patch the weights to 0 and 100. Roll back: patch them back.
  • Check it is attached: the route's status must report Accepted and ResolvedRefs as true. A route that looks right but is not attached does nothing, quietly.

The rule everyone else falls through to holds both versions and their weights:

YAML
- backendRefs:
  - name: shop-blue
    port: 80
    weight: 100
  - name: shop-green
    port: 80
    weight: 0

The release swaps the two numbers; a canary sets them to 90 and 10 first. The route's status tells you the gateway accepted the change before any user feels it.

Why this is where to start now#

It is the path the Kubernetes project recommends now that ingress-nginx is retired, most serious ingress and mesh projects implement it, and the CKA curriculum tests it. If you are choosing how to route traffic into a cluster today, start here rather than with Ingress annotations.

The series#

  1. Blue/green with a Service selector
  2. Blue/green with an Ingress
  3. Blue/green with the Gateway API: this article
  4. Blue/green with Istio

The diagram#

Drawn in archhy. Open it in archhy and press Make a copy to adapt it.

Go deeper#

Gazeek's full article has the Gateway and HTTPRoute YAML, the weight patch, the status to read and what goes wrong. Its CKA course has a guided Gateway API lab on a real kubeadm cluster.