🔧 DevOps

Rollback

Rollback

Reverting to a previous version when a deployment fails. An essential feature of CI/CD pipelines.

Detailed Explanation

A rollback is the act of reverting to a previous stable state when a deployment or change fails. As the last line of defense for system stability, it is an essential feature of every deployment system.

Depending on the target, rollbacks are divided into application rollback (redeploying the previous version), database rollback (reverting a migration), and infrastructure rollback (restoring configuration). Each differs in complexity and risk, and database rollback is the trickiest.

Kubernetes keeps Deployment history so you can roll back instantly with kubectl rollout undo. The number of ReplicaSets to retain is set with revisionHistoryLimit. In GitOps environments, committing a Git revert to the previous state triggers the rollback.

In practice, you set the rollback time objective (RTO) to within 5 minutes and document the rollback process. You define automatic rollback conditions (error rate above 5%, response time above 2 seconds, etc.) and integrate PagerDuty alerts.

Code Example

# Kubernetes 롤백
kubectl rollout history deployment/web-app          # 배포 히스토리 확인
kubectl rollout undo deployment/web-app             # 직전 버전으로 롤백
kubectl rollout undo deployment/web-app --to-revision=3  # 특정 버전으로 롤백
kubectl rollout status deployment/web-app           # 롤백 상태 확인

# Helm 롤백
helm history my-release                             # 릴리즈 히스토리
helm rollback my-release 2                          # revision 2로 롤백
helm rollback my-release 2 --wait --timeout 5m      # 타임아웃 설정

# ArgoCD 롤백 (GitOps)
argocd app rollback my-app 3                        # 특정 히스토리로 롤백
argocd app history my-app                           # 배포 히스토리 확인

# 자동 롤백 설정 (Argo Rollouts)
# analysis-template.yaml
apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata:
  name: success-rate
spec:
  metrics:
  - name: success-rate
    interval: 30s
    successCondition: result[0] >= 0.95   # 성공률 95% 이상
    failureLimit: 3                       # 3회 실패시 롤백
    provider:
      prometheus:
        address: http://prometheus:9090
        query: |
          sum(rate(http_requests_total{status=~"2.."}[5m])) /
          sum(rate(http_requests_total[5m]))

# DB 마이그레이션 롤백 (Flyway)
flyway undo                                         # 마지막 마이그레이션 취소
flyway undo -target=V003                            # 특정 버전까지 롤백

How It's Said in Practice

Senior: "The error rate spiked after the deployment. Let's roll back right away and analyze the cause."

Junior: "I ran helm rollback and the error rate is back to normal. The logs show the cause was a missing environment variable."

Interviewer: "What do you do if you need a rollback after a database schema change?"

Candidate: "My principle is backward-compatible migrations. I add columns as nullable and delete them in two steps, so the previous app version keeps working even after a rollback. For changes that involve data loss, I take a backup first and prepare a rollback script in advance."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

Reviewer: "revisionHistoryLimit is 2. Is that enough for production?"

Developer: "We've never actually rolled back two steps, but I'll raise it to 10 to be safe."

Cautions

Learn More