Blue-Green Deployment with Spring Boot : Strategy

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.

Blue-Green Deployment with Spring Boot

๐Ÿ”„ What is Blue-Green Deployment?

Blue-Green deployment maintains two environments:

  • Blue โ€“ current live (production) environment
  • Green โ€“ new version (inactive until ready)

You:

  1. Deploy new version to Green
  2. Run tests, health checks
  3. Switch traffic from Blue โ†’ Green
  4. 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):

Version 2 (Green):

Build and push Docker images:

๐Ÿงพ Step 2: Kubernetes Deployments

Blue Deployment

Green Deployment

๐ŸŒ Step 3: Dynamic Routing with Ingress

Use an Ingress controller (e.g., NGINX) to switch routing based on label:

When ready to switch:

  • Change serviceName from springboot-service-blue to springboot-service-green

You can automate this in your CI/CD pipeline.

โš™๏ธ Step 4: Create Services

Create separate Services for both:

๐Ÿงช Step 5: Validate Green Before Switching

Test with:

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:

โœ… Benefits Recap

BenefitExplanation
Zero downtimeNo impact to users during deployment
Easy rollbackJust point traffic back to Blue
Test in productionValidate real traffic on Green before switching
Better release safetyIdeal 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.