In this lesson, you will learn how to shift a small, controlled percentage of user traffic to a new version of your application using Ingress controller annotations to perform a canary release.
While Blue-Green deployments (our previous lesson) focus on cutting over entirely from one version to another, a Canary Release allows you to test a new version in production with a subset of real users. By leveraging your Ingress controller’s ability to inspect traffic, you can route, for example, 10% of requests to your "canary" version while the remaining 90% continue to hit the stable "production" version.
Most popular Ingress controllers (like NGINX) achieve this through specific annotations on a secondary Ingress resource. When you define an Ingress for the canary version, you point it to the same host as your production service, but add an annotation to specify the weight of traffic it should receive.
Practical Implementation
To route 10% of your traffic to a new deployment named my-app-canary, you would create an Ingress object like this:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-app-canary
annotations:
nginx.ingress.kubernetes.io/canary: "true"
nginx.ingress.kubernetes.io/canary-weight: "10"
spec:
rules:
- host: my-app.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-app-canary-svc
port:
number: 80
The nginx.ingress.kubernetes.io/canary: "true" annotation tells the controller that this is a side-car configuration to the existing stable Ingress. The canary-weight: "10" tells the controller to divert 10% of the traffic matched by the host my-app.com to this specific backend.
This approach is highly effective because it doesn't require complex service mesh logic for simple traffic splitting; the Ingress controller handles the load balancing decision at the entry point of your cluster. If the new version performs well, you can incrementally increase the weight (e.g., 25%, 50%, 100%) until you are ready to remove the canary Ingress and update the stable deployment.
Key Takeaway: Canary releases allow you to reduce deployment risk by routing a precise percentage of production traffic to a new version using Ingress controller annotations.