Blue-Green
Blue-Green Deployment
A zero-downtime deployment strategy that alternates between two environments. Immediate rollback is possible.
Blue-Green Deployment
A zero-downtime deployment strategy that alternates between two environments. Immediate rollback is possible.
Blue-Green deployment is a deployment strategy that runs two identical production environments (Blue and Green) to enable zero-downtime deployment and instant rollback. Popularized by Martin Fowler, this approach is a classic yet effective way to minimize deployment risk.
There is an environment that currently receives production traffic (e.g., Blue), and the new version is deployed to the standby environment (Green). After testing is complete, the load balancer or router is switched to send traffic to Green. If a problem occurs, switching back to Blue rolls back immediately.
In Kubernetes, it is implemented by changing the Service's selector or switching the Ingress backend. On AWS, it can be implemented with Elastic Beanstalk, ECS Blue/Green deployment, and Route 53 weighted routing.
In practice, care is needed when changing the database schema. A schema compatible with both Blue and Green must be maintained. The schema is changed gradually using the Expand-Contract pattern, or the approach is combined with feature flags.
#!/bin/bash
# Kubernetes Blue-Green λ°°ν¬ μ€ν¬λ¦½νΈ
NAMESPACE="production"
SERVICE="my-app"
NEW_VERSION="v2.0.0"
# νμ¬ νμ± λ°°ν¬ νμΈ (blue λλ green)
CURRENT=$(kubectl get svc ${SERVICE} -n ${NAMESPACE} \
-o jsonpath='{.spec.selector.version}')
if [ "$CURRENT" == "blue" ]; then
TARGET="green"
else
TARGET="blue"
fi
echo "νμ¬: $CURRENT -> μ ν λμ: $TARGET"
# μ λ²μ μ λκΈ° νκ²½μ λ°°ν¬
kubectl set image deployment/${SERVICE}-${TARGET} \
app=myregistry/${SERVICE}:${NEW_VERSION} -n ${NAMESPACE}
# λ°°ν¬ μλ£ λκΈ°
kubectl rollout status deployment/${SERVICE}-${TARGET} \
-n ${NAMESPACE} --timeout=300s
# ν¬μ€μ²΄ν¬ ν΅κ³Ό νμΈ
echo "ν¬μ€μ²΄ν¬ μν μ€..."
sleep 10
# νΈλν½ μ ν (Service selector λ³κ²½)
kubectl patch svc ${SERVICE} -n ${NAMESPACE} -p \
"{\"spec\":{\"selector\":{\"version\":\"${TARGET}\"}}}"
echo "νΈλν½μ΄ ${TARGET}μΌλ‘ μ νλμμ΅λλ€."
echo "λ‘€λ°±: kubectl patch svc ${SERVICE} -n ${NAMESPACE} \
-p '{\"spec\":{\"selector\":{\"version\":\"${CURRENT}\"}}}'"
Senior: "The last deployment rollback took 5 minutes, but if we switch to Blue-Green, we can roll back in 10 seconds. We only need to switch the traffic."
Junior: "Wouldn't the infrastructure cost double?"
Senior: "That's right, so some teams use Spot instances or scale up Green only during deployment."
Interviewer: "What is the difference between Blue-Green and Canary deployment?"
Candidate: "Blue-Green switches 100% of the traffic at once, while Canary gradually increases the traffic percentage. Blue-Green offers fast and simple rollback, but Canary can validate with a small group of users first, which spreads the risk further."
Take a mock interview on this topic β WIA SOOM AI Interview Β· Start for free
Reviewer: "There's a health check on the Green environment before the traffic switch. Instead of relying only on readinessProbe, how about also adding an actual API call test?"
Developer: "Good idea. In addition to the /health endpoint, I'll add a smoke test that calls a few key APIs."