Blue-Green Deployment in OpenShift
Run two application versions side by side and switch traffic with OpenShift Services and Routes.
Why This Matters
Run two application versions side by side and switch traffic with OpenShift Services and Routes.
In real projects, OpenShift is not only a place where containers run. It is the platform where developers, DevOps engineers, security teams, and operations teams collaborate around one application lifecycle. This lesson explains the concept, shows the practical commands, and gives you a production checklist you can reuse.
Where It Fits In The Learning Path
| Area | Details |
|---|---|
| Module | Build and Deployment |
| Primary user | Java developer, backend engineer, DevOps engineer |
| Main outcome | You can explain and apply Blue-Green Deployment in OpenShift in an OpenShift project |
| Example app | Spring Boot payments-api service |
Data Flow
flowchart LR
Dev[Developer] --> Git[Git Repository]
Git --> Build[OpenShift Build or CI Pipeline]
Build --> Image[Container Image]
Image --> Deploy[Deployment]
Deploy --> Pod[Running Pods]
Pod --> Service[Service]
Service --> Route[Route or Internal DNS]
Route --> User[Client or Consumer]
Step By Step Implementation
- Select the correct OpenShift project for the application.
- Prepare the Spring Boot artifact, container image, or deployment manifest.
- Apply the OpenShift resource.
- Verify Pods, Services, Routes, logs, and health checks.
- Promote the same pattern through dev, test, staging, and production.
Commands You Can Copy
oc label deployment payments-api-blue version=blue
oc label deployment payments-api-green version=green
oc set selector service/payments-api app=payments-api,version=green
Example Configuration
apiVersion: apps/v1
kind: Deployment
metadata:
name: payments-api
spec:
replicas: 2
selector:
matchLabels:
app: payments-api
template:
metadata:
labels:
app: payments-api
spec:
containers:
- name: payments-api
image: image-registry.openshift-image-registry.svc:5000/payments-dev/payments-api:latest
ports:
- containerPort: 8080
Input And Output Example
| Input | Expected output |
|---|---|
| Application source code or manifest | OpenShift resource is created or updated |
oc get pods |
Pods show Running or a clear failure reason |
oc logs deployment/payments-api |
Spring Boot startup logs and request logs are visible |
| Route or service URL | API returns a successful response or health status |
Production Checklist
- Use clear naming for project, app, service, and route resources.
- Keep environment-specific values outside the application jar.
- Configure readiness and liveness probes for every service.
- Set CPU and memory requests before moving to production.
- Store passwords, tokens, and keys in Secrets, not ConfigMaps.
- Use least privilege RBAC for users, pipelines, and ServiceAccounts.
- Validate logs, metrics, alerts, and rollback steps before release.
Common Mistakes
| Mistake | Better approach |
|---|---|
| Hard-coding environment values | Use ConfigMaps, Secrets, and environment variables |
| Deploying without probes | Add readiness, liveness, and startup probes |
| Running one replica in production | Use multiple replicas and anti-affinity when needed |
| Giving broad permissions | Use namespace-scoped roles and least privilege |
| Ignoring resource limits | Define requests and limits based on load testing |
Interview Notes
When explaining Blue-Green Deployment in OpenShift, connect the concept to operational value: faster releases, safer configuration, better security, and easier troubleshooting. Strong answers usually include both the OpenShift resource name and the runtime behavior it creates.
Quick Recap
- Blue-Green Deployment in OpenShift belongs to the Build and Deployment part of the OpenShift platform.
- The practical workflow is create, deploy, expose, observe, and improve.
- For Spring Boot applications, always think about configuration, security, health checks, scaling, and logs together.
Comments
Share a question, correction, or practical insight about this article.
Checking login status...
Loading approved comments...