Skip to content

Blue-Green or Canary deployment with Gateway API

blue-green

Kubernetes Gateway API addresses many shortcomings with the ingress controller and HTTPRoute configuration of Gateway API can be used to perform Blue-Green or Canary deployment.

Pre-requisites

- Kubernetes cluster with Gateway API (I am using Envoy Gateway)
- Gateway called `external-gateway`

Installing the application

In this example I have a simple Nginx Pod application with each version with different pages. 3 Versions of the app are installed and HTTP route configured to route all traffic to V1 installation

  • V1 : Blue
  • V2 : Green
  • V3 : Red
helm install myapp-v1 bluegreen --repo=https://vettom.github.io/demohelmrepo/ --version 1.0.0
helm install myapp-v2 bluegreen --repo=https://vettom.github.io/demohelmrepo/ --version 2.0.0
helm install myapp-v3 bluegreen --repo=https://vettom.github.io/demohelmrepo/ --version 3.0.0

Configure HTTP route

Here HTTP route with single backend. Apply the route and verify application can be accessed.

myapp_route.yaml

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: myapp-route-http
  namespace: default
spec:
  hostnames:
    - bluegreen.vettom.online
  parentRefs:
    - group: gateway.networking.k8s.io
      kind: Gateway
      name: external-gateway
      namespace: gateway
  rules:
    - backendRefs:
        - name: myapp-v1-bluegreen
          port: 8080
          weight: 80
        - name: myapp-v2-bluegreen
          port: 8080
          weight: 20
    - matches:
        - headers:
            - name: traffic
              type: Exact
              value: test
      backendRefs:
        - name: myapp-v3-bluegreen
          port: 8080
          weight: 1

In the above httpRoute configuration, 80% of the traffic will be routed to V1 and 20% to V2. If you like to switch all traffic to V2, update V1 weight as '0'.

Backend configuration for V3 requires specific Header to be passed. This enables you to open up new version to specific set of users/testers while live version continue to serve content. When user pass header traffic=test, all their requests will be routed to V3 page.