codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
☸️

Kubernetes

19 / 82 topics
17Managing Multiple Clusters18Introducing Istio Service Mesh19Canary Deployments in Kubernetes20Blue-Green Deployments in Kubernetes
Tutorials/Kubernetes/Canary Deployments in Kubernetes
☸️Kubernetes

Canary Deployments in Kubernetes

Updated 2026-05-15
10 min read

Canary Deployments in Kubernetes

Introduction

In the world of software development, deploying new application versions can be risky. A canary deployment is a technique used to gradually roll out new versions of applications to a small subset of users before rolling them out to everyone. This approach helps identify potential issues early and ensures that the majority of your user base remains unaffected by any problems.

Kubernetes provides several mechanisms to facilitate canary deployments, including using different deployment strategies like RollingUpdate, Canary, and Blue-Green. In this tutorial, we will focus on how to implement a canary deployment using Kubernetes.

Concept

A canary deployment involves running the new version of your application alongside the existing version. Users are gradually shifted from the old version to the new one based on specific criteria such as traffic weight or user segments. This allows you to monitor the performance and stability of the new version before fully rolling it out.

Kubernetes achieves this by creating multiple deployments for different versions of your application and using a service to route traffic between them. The service can be configured to direct a percentage of traffic to the canary deployment, allowing you to gradually increase the exposure of the new version.

Examples

Step 1: Create the Base Deployment

First, let's create a base deployment for our application. This will represent the current stable version running in production.

YAML
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4name: my-app-base
5spec:
6replicas: 3
7selector:
8 matchLabels:
9 app: my-app
10template:
11 metadata:
12 labels:
13 app: my-app
14 version: base
15 spec:
16 containers:
17 - name: my-app-container
18 image: my-app-image:1.0
19 ports:
20 - containerPort: 80

Apply this deployment using the following command:

Terminal
kubectl apply -f base-deployment.yaml

Step 2: Create the Canary Deployment

Next, create a canary deployment for the new version of your application.

YAML
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4name: my-app-canary
5spec:
6replicas: 1
7selector:
8 matchLabels:
9 app: my-app
10template:
11 metadata:
12 labels:
13 app: my-app
14 version: canary
15 spec:
16 containers:
17 - name: my-app-container
18 image: my-app-image:2.0
19 ports:
20 - containerPort: 80

Apply this deployment using the following command:

Terminal
kubectl apply -f canary-deployment.yaml

Step 3: Configure the Service

Now, configure a service to route traffic between the base and canary deployments. You can use Kubernetes' built-in load balancing capabilities to direct a percentage of traffic to the canary deployment.

YAML
1apiVersion: v1
2kind: Service
3metadata:
4name: my-app-service
5spec:
6selector:
7 app: my-app
8ports:
9- protocol: TCP
10 port: 80
11 targetPort: 80
12type: LoadBalancer

Apply this service using the following command:

Terminal
kubectl apply -f service.yaml

Step 4: Gradually Increase Canary Traffic

To gradually increase traffic to the canary deployment, you can adjust the number of replicas in the canary deployment and monitor its performance. If everything looks good, you can continue increasing the number of replicas until all traffic is routed to the new version.

Terminal
kubectl scale deployment my-app-canary --replicas=2

Step 5: Monitor and Rollout

Monitor the canary deployment for any issues using Kubernetes tools like kubectl logs, kubectl describe, or monitoring solutions integrated with your CI/CD pipeline. If everything is stable, you can proceed to roll out the new version fully.

Terminal
kubectl scale deployment my-app-base --replicas=0

What's Next?

After mastering canary deployments, you might want to explore other deployment strategies such as blue-green deployments in Kubernetes. Blue-green deployments involve running two identical environments (blue and green) and switching traffic between them, which provides a safer way to roll out new versions without downtime.

Stay tuned for more tutorials on advanced Kubernetes topics!


PreviousIntroducing Istio Service MeshNext Blue-Green Deployments in Kubernetes

Recommended Gear

Introducing Istio Service MeshBlue-Green Deployments in Kubernetes