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
A canary release exposes a small part of a service to a new version before a full release. Selecting both old and new Pods behind one Service is simple, but replica counts do not guarantee an exact request percentage.
Before you start
Create canary-lab in a test cluster. Choose stable and candidate images, identify how you will distinguish their responses or metrics, and decide when to stop the test.
Step 1: Create separate Deployments
Save this as canary.yaml and apply it:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-stable
namespace: canary-lab
spec:
replicas: 3
selector:
matchLabels:
app: web
track: stable
template:
metadata:
labels:
app: web
track: stable
spec:
containers:
- name: web
image: nginx:1.28.0
ports:
- name: http
containerPort: 80
readinessProbe:
httpGet:
path: /
port: http
resources:
requests:
cpu: 100m
memory: 64Mi
limits:
memory: 128Mi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-canary
namespace: canary-lab
spec:
replicas: 1
selector:
matchLabels:
app: web
track: canary
template:
metadata:
labels:
app: web
track: canary
spec:
containers:
- name: web
image: nginx:1.28.0
ports:
- name: http
containerPort: 80
readinessProbe:
httpGet:
path: /
port: http
resources:
requests:
cpu: 100m
memory: 64Mi
limits:
memory: 128Mi
---
apiVersion: v1
kind: Service
metadata:
name: web
namespace: canary-lab
spec:
selector:
app: web
ports:
- port: 80
targetPort: http
Run kubectl apply -f canary.yaml. The Deployments have separate ownership labels while the Service selects the shared application label.
Step 2: Check which Pods receive traffic
Run:
kubectl -n canary-lab rollout status deployment/web-canary --timeout=180s
kubectl -n canary-lab get pods -l app=web -L track
kubectl -n canary-lab get endpointslices -l kubernetes.io/service-name=web
kubectl -n canary-lab describe deployment web-canary
Send a controlled set of requests through the Service and compare errors and response times by version. Persistent connections and readiness affect the split; three stable Pods and one candidate do not promise exactly 25 percent of requests.
Step 3: Promote or stop
If the candidate meets the agreed checks, update the main release through your normal configuration. If it fails, scale down or remove the candidate and verify the Service endpoints. Already established connections may not stop immediately.
Check the result
Confirm the actual endpoint population and application behavior. For controlled traffic weights, use a routing layer such as Gateway API with a compatible controller.
Conversation
0 commentsNo comments yet. Start the conversation below.