When deploying Spring Boot applications in production, downtime or buggy rollouts can damage user trust. Blue-Green Deployment is a proven strategy that allows for zero-downtime deployments, quick rollback, and smooth version transitions.
In this guide, youโll learn:
- What Blue-Green deployment is
- How to implement it for Spring Boot using Kubernetes, NGINX, or cloud load balancers
- Full YAML and CI/CD integration examples
- Best practices for observability and rollback
All examples use com.kscodes.springboot.containers as the base package.

๐ What is Blue-Green Deployment?
Blue-Green deployment maintains two environments:
- Blue โ current live (production) environment
- Green โ new version (inactive until ready)
You:
- Deploy new version to Green
- Run tests, health checks
- Switch traffic from Blue โ Green
- Keep Blue available for rollback
๐งฐ Prerequisites
- Dockerized Spring Boot app
- Kubernetes cluster (Minikube, GKE, etc.)
- Ingress controller (or NGINX)
- CI/CD pipeline (optional)
- Helm (optional)
๐ฆ Step 1: Spring Boot Sample App
Weโll deploy two versions of the app with minor changes.
Version 1 (Blue):
@GetMapping("/")
public String home() {
return "Welcome to the BLUE version!";
}
Version 2 (Green):
@GetMapping("/")
public String home() {
return "Welcome to the GREEN version!";
}
Build and push Docker images:
docker build -t kscodes/springboot-blue:1.0 .
docker push kscodes/springboot-blue:1.0
docker build -t kscodes/springboot-green:2.0 .
docker push kscodes/springboot-green:2.0
๐งพ Step 2: Kubernetes Deployments
Blue Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: springboot-blue
spec:
replicas: 2
selector:
matchLabels:
app: springboot
version: blue
template:
metadata:
labels:
app: springboot
version: blue
spec:
containers:
- name: springboot
image: kscodes/springboot-blue:1.0
ports:
- containerPort: 8080
Green Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: springboot-green
spec:
replicas: 2
selector:
matchLabels:
app: springboot
version: green
template:
metadata:
labels:
app: springboot
version: green
spec:
containers:
- name: springboot
image: kscodes/springboot-green:2.0
ports:
- containerPort: 8080
๐ Step 3: Dynamic Routing with Ingress
Use an Ingress controller (e.g., NGINX) to switch routing based on label:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: springboot-ingress
spec:
rules:
- host: springboot.kscodes.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: springboot-service-green
port:
number: 80
When ready to switch:
- Change
serviceNamefromspringboot-service-bluetospringboot-service-green
You can automate this in your CI/CD pipeline.
โ๏ธ Step 4: Create Services
Create separate Services for both:
# blue-service.yaml
apiVersion: v1
kind: Service
metadata:
name: springboot-service-blue
spec:
selector:
app: springboot
version: blue
ports:
- protocol: TCP
port: 80
targetPort: 8080
# green-service.yaml
apiVersion: v1
kind: Service
metadata:
name: springboot-service-green
spec:
selector:
app: springboot
version: green
ports:
- protocol: TCP
port: 80
targetPort: 8080
๐งช Step 5: Validate Green Before Switching
Test with:
kubectl port-forward svc/springboot-service-green 8080:80
curl http://localhost:8080
Ensure logs, metrics, and endpoints respond correctly.
๐ Step 6: Switch Traffic
Update the Ingress YAML or route controller to point to springboot-service-green.
Rollback? Just switch back to springboot-service-blue.
๐ Optional: Automate with GitOps / CI/CD
You can integrate Blue-Green deployment in:
- GitHub Actions
- Argo CD
- Jenkins pipelines
Sample GitHub Action:
- name: Switch Ingress to Green
run: |
kubectl apply -f ingress-green.yaml
โ Benefits Recap
| Benefit | Explanation |
|---|---|
| Zero downtime | No impact to users during deployment |
| Easy rollback | Just point traffic back to Blue |
| Test in production | Validate real traffic on Green before switching |
| Better release safety | Ideal for mission-critical apps |
๐ Summary
In this guide, you implemented the strategy of Blue-Green Deployment with Spring Boot using Kubernetes and NGINX. This method ensures zero downtime, allows quick rollbacks, and improves release confidence. With YAML, labels, and traffic switching, you can easily automate your deployment process.
In the next post, weโll automate Spring Boot deployments using Jenkins CI/CD pipelines.