- Blue-Green deployment is a strategy used in Kubernetes (and other environments) to reduce downtime and risk when deploying new versions of an application.
- It involves maintaining two separate environments, which are referred to as Blue and Green.
- Blue Environment: This is the live environment, where the current version of your application is running..
- Green Environment: The new version of the application is deployed to the Green environment. During this phase, there is no impact on the users accessing the Blue environment.
- Test the Green Environment: Once the Green environment is up, it is fully tested to ensure the new version works as expected.
- Switch traffic: After validating that the Green environment is stable, the routing of user traffic is switched from Blue to Green. Now, the Green environment becomes the live production environment, and users interact with the new version.
| Pro's | Con's |
|---|---|
| Instant rollout/rollback | Requires double the resources |
| Avoid versioning issue, change entire cluster state in one go | Proper test of entire platform should be done before releasing to the production environment. |
Note
This deployment strategy is suitable for Production environment.
-
EC2 Instance with Ubuntu OS
-
Docker installed & Configured
-
Kind Installed
-
Kubectl Installed
-
Kind Cluster running(Use
kind-config.ymlfile present in this root directory.)
Note
You have to go inside root dir of this repo and create Kind Cluster using command: kind create cluster --config kind-config.yml --name dep-strg
-
Create a namespace first by using:
kubectl apply -f blue-green-ns.yml
-
Apply the both deployment manifests (
online-shop-without-footer-blue-deployment.yamlandonline-shop-green-deployment.yaml) present in the current directory.kubectl apply -f online-shop-without-footer-blue-deployment.yaml kubectl apply -f online-shop-green-deployment.yaml
-
Open a new tab of terminal and run the watch command to monitor the deployment
watch kubectl get pods -n blue-green-ns
-
It will deploy
online shop web page without footer(Blue environment) andonline shop web page with footeras a new feature (Green environment), now try to access the blue environment web page on browser. -
Run this command to get all resources created in
blue-green-nsnamespace.kubectl get all -n blue-green-ns
-
Forward the
online-shop-blue-deployment-servicesvc Port with Nodeportkubectl port-forward --address 0.0.0.0 svc/online-shop-blue-deployment-service 30001:3001 -n blue-green-ns & -
Open the inbound rule for port 30001 in that EC2 Instance and check the application(without footer online shop) at URL:
http://<Your_Instance_Public_Ip>:30001
-
Without footer online shop app image:
-
Forward the
online-shop-green-deployment-servicesvc Port with Nodeportkubectl port-forward --address 0.0.0.0 svc/online-shop-green-deployment-service 30000:3000 -n blue-green-ns & -
Open the inbound rule for port 30000 in that EC2 Instance and check the application(With footer online shop) at URL:
http://<Your_Instance_Public_Ip>:30000
-
With the footer online shop image:
Note
Check the URL and port carefully
-
Now, go to the
online-shop-without-footer-blue-deployment.yamlmanifest file and edit the service's selector field withonline-shop-greenselector. -
Previous selector:
-
Current selector:
-
Apply
online-shop-without-footer-blue-deployment.yamlkubectl apply -f online-shop-without-footer-blue-deployment.yaml
-
Kill all the port-forwarding using the command:
pkill -f "kubectl port-forward" -
Now again, forward the
online-shop-blue-deployment-servicesvc Port with Nodeportkubectl port-forward --address 0.0.0.0 svc/online-shop-blue-deployment-service 30001:3001 -n blue-green-ns & -
Check now, the application has added a new feature as
with footer online shop, as it previously did not have a footer, but it is now added as a feature, check at URL:http://<Your_Instance_Public_Ip>:30001
-
Reload the webpage, you will see
with footer online web pagethis time at NodePort: 30001. This means you have successfully switched traffic from a blue environment to a green environment.
-
Deleting Kind Cluster:
kind delete cluster --name dep-strg
Note
If you cannot access the web app after the update, check your terminal — you probably encountered an error like:
error: lost connection to podDon’t worry! This happens because we’re running the cluster locally (e.g., with Kind), and the kubectl port-forward session breaks when the underlying pod is replaced during deployment (especially with Recreate strategy).
🔁 Just run the kubectl port-forward command again to re-establish the connection and access the app in your browser.
✅ This issue won't occur when deploying on managed Kubernetes services like AWS EKS, GKE, or AKS, because in those environments you usually expose services using NodePort, LoadBalancer, or Ingress — not kubectl port-forward.





