
- Deploy two versions of the same application:
coffee(v1) andcoffeev2(v2). - Create an
HTTPRouteattached to the Gateway that splits traffic between the two Services usingweightto simulate canary rollouts. - Drive requests to the route and observe how the Gateway distributes traffic as you change weights.
- Gateway API provides first‑class routing primitives (
HTTPRoute,TCPRoute, etc.) that support weighted backend splitting. - Weighted routing enables gradual rollouts without changing client endpoints — zero downtime and safer deployments.
- Only v1 (
coffee) is running and noHTTPRouteexists yet. The gateway is already deployed.
Step 1 — Deploy the v2 application
Create a Deployment and Service for
coffeev2 (v2 of the same app). This manifest uses the same image as v1, exposes port 8080 in the pod and Service port 80.
coffeev2-app.yaml:
HTTPRoute named splitroute that attaches to the existing gateway (sectionName http) and splits requests for host cafe.example.com on the /coffee path between two backend Services using weight.
Initial canary route (75/25):
- Use
curlwith--resolveto send requests to the gateway address while setting theHostheader tocafe.example.com. In these examples we uselocalhost:8080. If your Gateway is exposed as a NodePort (e.g.,31437) or you prefer toport-forward, update the port accordingly. - The app response includes
Server name(pod name) andServer addressso you can identify which backend served each request.
--resolve.
If your Gateway is exposed on a NodePort (for example
31437) or through a load balancer, replace 8080 in the examples with the Gateway’s listening port, or use kubectl port-forward to map the gateway to localhost:8080.Weighted traffic splitting is probabilistic: a 75/25 weight is an approximate distribution. With a small sample of requests you may see variance; the distribution converges with higher request volume.
HTTPRoute weights to gradually shift traffic toward coffeev2. Each change is a single manifest edit and kubectl apply.
Example: change weights to 90/10
coffeev2 is validated and healthy, update the route so all traffic goes to v2 and v1 receives none.
Final route for 0/100:
- Start small: begin with a low percentage (for example
1%→5%→25%) and increase as confidence grows. - Monitor errors, latency, logs, and business metrics continuously during each step.
- Automate and track changes via GitOps (ArgoCD, FluxCD) for auditable rollouts and easy rollbacks.
- Remember weights are probabilistic. For precision testing use a sufficiently large request volume or a traffic generator.
- Consider session affinity or consistent hashing if your app requires sticky sessions during canaries.
- Gateway API specification: https://gateway-api.sigs.k8s.io/
- NGINX Gateway documentation: https://www.nginx.com/products/nginx-kubernetes-gateway/
- Kubernetes documentation: https://kubernetes.io/docs/
- GitOps with ArgoCD: https://argoproj.github.io/argo-cd/
- FluxCD: https://fluxcd.io/