هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
The quick answer
Step by step
- Two Deployments, shared label —
api-stableandapi-canaryboth haveapp: api(plustrack: stable|canary); the Service selects onlyapp: api, so it spreads traffic over all Pods. The canary's share is its share of Pods. - Start small (quick answer) — 1 canary Pod of 10. Watch the canary's metrics separately (by the
tracklabel): error rate, latency p95, logs. - Increase — 3 of 10, then 5 of 10, then make the canary the new stable (update
api-stable's image, scale the canary to 0). - Abort — scale the canary to 0 (last line); users go back to stable at once.
- Exact percentages — Pod counts are rough. ingress-nginx can split by weight with a second Ingress:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: api-canary
annotations:
nginx.ingress.kubernetes.io/canary: "true"
nginx.ingress.kubernetes.io/canary-weight: "10"
spec:
ingressClassName: nginx
rules:
- host: api.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service: { name: api-canary, port: { number: 80 } }Here api-canary is a separate Service that selects only track: canary. Change the weight to 25, 50, 100. A header (canary-by-header) lets testers reach the canary on purpose.
- Decide with numbers — before the release, write down the rule: "abort if canary error rate > 1 % or p95 > 400 ms for 5 minutes".
- Automate — Argo Rollouts or Flagger run the steps, query Prometheus, and roll back automatically when the metrics are bad. Gateway API
HTTPRouteweights are the newer standard way to split traffic.
Check that it worked
kubectl -n shop get pods -l app=api -L track shows 9 stable and 1 canary Pod; the request logs or metrics by track show about 10 % of requests on the canary; with the ingress weight at 10, about 1 in 10 test requests (for i in $(seq 100); do curl -s https://api.example.com/version; done | sort | uniq -c) answers with the new version.
Common problems
| Problem | Cause | Fix |
|---|---|---|
| Share is not what you expected | Traffic split by Pods, connections are sticky/long. | Use ingress weights; expect rough numbers with replica splits. |
| Canary metrics hidden in the average | Metrics not split by version. | Label metrics/logs with track or version. |
| Canary ingress ignored | Annotations on the main Ingress, or a different host/path. | Separate Ingress with the same host and path plus canary annotations. |
| Users switch between versions | Each request may hit another Pod. | Session affinity, or make both versions compatible. |
| Bad canary not noticed | No decision rule, nobody watching. | Written abort rule; automated analysis (Argo Rollouts/Flagger). |
| Schema change breaks stable | Canary migrated the database. | Expand/contract migrations. |
Go further
- Command pages: kubectl, curl.
- Next how-tos: Do a blue-green deployment in Kubernetes, Define an SLO and an error budget, Expose an app with an Ingress and TLS, Promote a release from staging to production.
- Learn it: CKA — Ingress, CKA — Gateway API, CKA — Rollouts.
1How do two Deployments behind one Service make a canary?
Both share the label the Service selects, so traffic is spread over all their Pods; the canary's share is its share of Pods.
2Why write the abort rule before the release?
A clear rule (for example error rate above 1 % for 5 minutes) makes the stop decision fast and objective.