K8s by Example: Canary Deployments
| Canary deployments release new versions to a small subset of traffic first. If the canary is healthy, gradually increase traffic until full rollout. If problems occur, roll back with minimal impact. Use for: risk mitigation, A/B testing, feature validation, compliance requirements. |
| canary-basic.yaml | |
| Basic canary with two Deployments sharing a Service. Both have the same app label so the Service routes to both. Adjust replica counts to control traffic split (9 stable + 1 canary = 10% canary traffic). | |
| canary-service.yaml | |
| The Service selects Pods by the | |
| canary-ingress.yaml | |
| Ingress-based canary with nginx-ingress annotations. The | |
| canary-header.yaml | |
| Header-based canary routing. Only requests with specific headers go to canary. Useful for internal testing before public rollout. Combine with weight for staged rollout. | |
| terminal | |
| For automated canary with analysis, install Argo Rollouts. It provides the Rollout CRD which replaces Deployment and adds canary/blue-green strategies with automatic promotion and rollback. | |
| canary-analysis.yaml | |
| Argo Rollouts provides automated canary analysis. Define metrics to check (error rate, latency) and thresholds. The rollout automatically progresses or rolls back based on analysis results. | |
| analysis-template.yaml | |
| AnalysisTemplate defines how to measure canary health. Query Prometheus for error rates, compare against thresholds. If the analysis fails, the rollout automatically aborts. | |
| terminal | |
| Monitor canary progress with kubectl or the Argo Rollouts CLI. Watch traffic shifting, analysis results, and rollout status. Manually promote or abort if needed. | |