Version note: examples use the Kubernetes v1.35 documentation snapshot, not necessarily the newest release. Check current support and component compatibility. These commands were not tested on a live cluster.
What this guide covers
Gateway API can assign relative traffic weights to two backend Services. This separates the routing split from the number of Pods in each application version.
Before you start
Use the stable and canary Deployments from the canary guide. Install compatible Gateway API definitions and a controller, and create a working Gateway named edge in canary-lab. The controller must support weighted backend references.
Step 1: Create one Service per version
Save the Services below as services.yaml, then apply them:
apiVersion: v1
kind: Service
metadata:
name: web-stable
namespace: canary-lab
spec:
selector:
app: web
track: stable
ports:
- name: http
port: 80
targetPort: http
---
apiVersion: v1
kind: Service
metadata:
name: web-canary
namespace: canary-lab
spec:
selector:
app: web
track: canary
ports:
- name: http
port: 80
targetPort: http
Use kubectl apply -f services.yaml. Each Service should have ready endpoints for only its own version.
Step 2: Set routing weights
Save this as route.yaml:
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: web-release
namespace: canary-lab
spec:
parentRefs:
- name: edge
sectionName: http
hostnames:
- web.lab.example
rules:
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: web-stable
port: 80
weight: 90
- name: web-canary
port: 80
weight: 10
Update the hostname and parent Gateway to your environment. Weights are relative; they are not a promise that every small group of requests has exactly that split.
Step 3: Apply and check the route
Run:
kubectl get crd httproutes.gateway.networking.k8s.io
kubectl -n canary-lab get gateway edge
kubectl apply --dry-run=server -f route.yaml
kubectl apply -f route.yaml
kubectl -n canary-lab get httproute web-release -o yaml
kubectl -n canary-lab get endpointslices
Check the route’s Accepted and ResolvedRefs conditions, the Gateway listener and backend endpoints. A valid YAML file is not enough if the controller rejects or cannot implement it.
Step 4: Observe and adjust
Send controlled requests through the Gateway hostname, not directly to a Pod. Compare results by version. Adjust weights in the saved route configuration and reapply it. Keep the previous version running while a rollback may be needed.
Check the result
The public route should reach both intended Services approximately according to their weights over enough requests. Keep application compatibility and capacity checks separate from routing.
Conversation
0 commentsNo comments yet. Start the conversation below.