In this lesson, you will learn how to shift a controlled percentage of live production traffic to a new version of your application using Ingress annotations.
The Canary Concept
A canary deployment is a risk-mitigation strategy where you release a new version of your service to a small subset of users before rolling it out to your entire infrastructure. If the new version (the "canary") performs well, you gradually increase the traffic share until it handles 100% of requests. If issues arise, you can immediately revert traffic to the stable version.
Implementing via NGINX Ingress
When using the NGINX Ingress controller, you manage this transition using specialized annotations. You define two Ingress resources: one for your stable production service and one for the canary version.
By adding the nginx.ingress.kubernetes.io/canary: "true" annotation to the canary Ingress, the controller identifies it as a secondary route. You then use the nginx.ingress.kubernetes.io/canary-weight annotation to specify the traffic split:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: app-canary
annotations:
nginx.ingress.kubernetes.io/canary: "true"
nginx.ingress.kubernetes.io/canary-weight: "10"
spec:
rules:
- host: myapp.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: app-v2
port:
number: 80
In this example, 10% of requests hitting myapp.com will be routed to the app-v2 service, while the remaining 90% continue to flow to the stable version defined in your primary Ingress.
Managing the Rollout
As you gain confidence in the new version, you manually update the canary-weight value (e.g., from 10 to 50, then to 100). Once the weight reaches 100, the new version effectively becomes your production service, and you can remove the old Ingress definition and the canary annotations. This approach provides a granular "knob" to control risk without requiring a full service mesh or complex deployment logic.
Key Takeaway: Canary deployments use Ingress-level annotations to route a percentage of traffic to a new service version, allowing for safe, incremental production testing.