Kubernetes Blue/Green Deployments: A Simple Guide
When it comes to deploying applications in Kubernetes, maintaining uptime and minimizing disruptions during updates is crucial. Kubernetes offers a powerful built-in feature known as Deployments, which supports rolling updates to deploy new versions of applications with minimal impact. However, there are scenarios where a more direct approach is required, especially for legacy applications. This is where Kubernetes Blue/Green Deployments comes in.
In this guide, we will explore the concept of blue/green deployments, how they work in Kubernetes, and how to implement them effectively to ensure smooth updates with zero downtime.

What is a Kubernetes Blue/Green Deployment?
A Kubernetes Blue/Green Deployment is a method of deploying new versions of an application with minimal disruption. Unlike rolling updates, where new versions are gradually rolled out, blue/green deployments involve running two identical environments side by side: one running the current version (blue) and the other the new version (green). The traffic is then switched from the blue version to the green version, ensuring a seamless transition.
This approach is especially beneficial when you need to ensure that legacy applications or mission-critical services have no downtime during the update process.
Step 1: Creating the Blue Deployment
To get started with a Kubernetes blue/green deployment, you need to set up a blue deployment. This is your current application version that is actively serving traffic. In Kubernetes, this is typically done using a Deployment and Service.
Here’s an example of a simple blue.yaml file to define a blue deployment for version 1.10 of Nginx:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-1.10
spec:
replicas: 2
template:
metadata:
labels:
name: nginx
version: "1.10"
spec:
containers:
- name: nginx
image: nginx:1.10
ports:
- name: http
containerPort: 80
Apply this deployment with:
kubectl apply -f blue.yaml
Once the deployment is created, you can expose it using a Kubernetes Service to allow traffic to reach the pods:
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
run: nginx
spec:
type: NodePort
ports:
- port: 8080
targetPort: 80
protocol: TCP
name: http
- port: 443
protocol: TCP
name: https
selector:
run: nginx
version: "1.10"
type: LoadBalancer
Apply the service configuration:
kubectl apply -f service.yaml
This will set up a LoadBalancer service, making your application accessible outside the cluster.
Step 2: Creating the Green Deployment
Next, you’ll create the green deployment, which will run the new version of your application (in this case, Nginx 1.11). The process is similar to the blue deployment but with different labels to distinguish the two environments.
Here’s an example of a green.yaml file for version 1.11 of Nginx:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-1.11
spec:
selector:
matchLabels:
run: nginx-1.11
replicas: 2
template:
metadata:
labels:
run: nginx-1.11
spec:
containers:
- name: nginx
image: nginx:1.11
ports:
- name: http
containerPort: 80
Apply the green deployment:
kubectl apply -f green.yaml
At this point, the green deployment is running, but the service is still pointing to the blue version.
Step 3: Switching Traffic to the Green Deployment
To switch traffic from the blue version to the green version, you need to update the service.yaml to point to the new version (green) by adjusting the selector labels. Change the version to “1.11” as shown below:
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
run: nginx
spec:
type: NodePort
ports:
- port: 8080
targetPort: 80
protocol: TCP
name: http
- port: 443
protocol: TCP
name: https
selector:
run: nginx
version: "1.11"
type: LoadBalancer
After updating the service, apply the changes:
kubectl apply -f service.yaml
This step will immediately switch traffic to the new version (green). You can test this by querying the external IP of your service:
EXTERNAL_IP=$(kubectl get svc nginx -o jsonpath="{.status.loadBalancer.ingress[*].ip}")
curl -s http://$EXTERNAL_IP/version | grep nginx
You should see that the new version (1.11) is now serving traffic.
Step 4: Clean Up
Once the green deployment is successfully serving traffic, you can safely remove the old blue deployment:
kubectl delete deployment nginx-1.10
If needed, you can delete the old services as well to avoid clutter.
Kubernetes Blue/Green Deployments with ZippyOPS
If you are managing Kubernetes deployments at scale, integrating DevOps practices is essential. ZippyOPS provides expert consulting, implementation, and managed services, helping organizations streamline their deployment processes with tools like DevOps, DevSecOps, AIOps, and more.
ZippyOPS can assist with:
- Automating deployments through CI/CD pipelines
- Ensuring robust security and infrastructure management
- Implementing DataOps and MLOps for data-driven applications
- Optimizing cloud and microservices architecture
For more information, visit ZippyOPS Services or explore their solutions.
Conclusion on Kubernetes Blue/Green Deployments
Kubernetes Blue/Green Deployment is an effective strategy for ensuring smooth updates with minimal downtime, especially for critical applications. By following the steps outlined in this guide, you can implement a robust deployment pipeline, seamlessly transitioning from one version to the next. If you’re looking to take your Kubernetes deployments to the next level, consider leveraging expert consulting services from ZippyOPS for automation, security, and infrastructure management.
For inquiries, contact: sales@zippyops.com



