Switching Traffic to Deployment Version 2

We can update our service.yaml as below.

apiVersion: v1
kind: Service
metadata:
name: blue-green-dep-service
spec:
ports:
- port: 8080
targetPort: 8080
selector:
app: dep-v2

After that we can use the same command to update our service,

kubectl apply -f service.yaml

At this point there shouldn’t be any difference but when we visit http://localhost:8080 again, version 2 of our app is live now. Make sure port forwarding is still on.

In any case if you want to switch to deployment version 1, we only need to update our service file. Then, we should remove the other version of the deployment that will not be used anymore.

kubectl delete -f dep-v1.yaml

What is Kubernetes Blue Green Deployment?

Blue-green deployment is a software deployment strategy that involves running two identical production environments, known as “blue” and “green.” At any given time, only one of these environments serves live traffic, while the other remains idle or serves only non-production traffic (e.g., testing or staging).

Similar Reads

What is Kubernetes?

Kubernetes is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications....

What is a Deployment in Kubernetes?

In Kubernetes, a Deployment is a resource that manages the lifecycle of an application by defining its desired state. It provides declarative updates for Pods (the smallest deployable units of computing) and ReplicaSets (which ensure the desired number of replicas are running)....

What is a Service in Kubernetes?

A Kubernetes Service is an abstraction that defines a logical set of Pods and a policy by which to access them. It acts as a stable endpoint for accessing the applications running in a Kubernetes cluster, regardless of the underlying Pod’s IP address or location within the cluster....

What is Blue-Green Deployment in Kubernetes?

the is a deployment strategy used in Kubernetes to minimize downtime and reduce the risk associated with deploying new versions of an application. It involves running two identical production environments, referred to as “Blue” and “Green,” where only one environment is live at any given time....

Create Deployment Version 1

This will act as our current stable version of the application. We will create a deployment for this and use the publicly available (guybarrette/hello-app) docker image available on the docker hub....

Creating a Service

In order to access our application from the outside world, we need to make use of a Kubernetes service. It will select all pod having app: dep-v1 selector....

Creating Deployment Version 2

Create a new file dep-v2.yaml with the following content,...

Switching Traffic to Deployment Version 2

We can update our service.yaml as below....

Kubernetes Blue Green Deployment – FAQ’s

What are the main benefits of using Blue-Green Deployments?...