πŸ”§ DevOps

Rolling Update

Rolling Update

A deployment strategy that replaces instances sequentially. Zero downtime.

Detailed Explanation

Rolling Update is a zero-downtime deployment strategy that replaces existing instances one by one when deploying a new version of an application. It is the most basic yet reliable way to update gradually while maintaining service availability.

In Kubernetes, Rolling Update is the default deployment strategy, and the maxSurge and maxUnavailable parameters control how many Pods are created/deleted at once. For example, with 10 Pods, setting maxSurge=2 and maxUnavailable=1 means up to 12 Pods exist and at least 9 are always available. This lets you provide stable service even during traffic spikes.

Code Example

Kubernetes Rolling Update configuration

# deployment-rolling.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-app
spec:
  replicas: 6
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 2        # μ΅œλŒ€ μΆ”κ°€ 생성 Pod 수
      maxUnavailable: 1  # μ΅œλŒ€ μ‚¬μš© λΆˆκ°€ Pod 수
  selector:
    matchLabels:
      app: web-app
  template:
    metadata:
      labels:
        app: web-app
    spec:
      containers:
      - name: web
        image: myapp/web:v2.0.0
        ports:
        - containerPort: 80
        readinessProbe:
          httpGet:
            path: /ready
            port: 80
          initialDelaySeconds: 5
          periodSeconds: 5
          successThreshold: 1
          failureThreshold: 3
        resources:
          requests:
            cpu: 100m
            memory: 128Mi
          limits:
            cpu: 500m
            memory: 512Mi
      terminationGracePeriodSeconds: 30

Monitoring deployment progress

#!/bin/bash
# rolling-update-monitor.sh

DEPLOYMENT="web-app"
NAMESPACE="production"

# ν˜„μž¬ 버전 확인
echo "=== ν˜„μž¬ 배포 μƒνƒœ ==="
kubectl get deployment $DEPLOYMENT -n $NAMESPACE \
  -o jsonpath='{.spec.template.spec.containers[0].image}'
echo ""

# μƒˆ 버전 배포
echo "=== v2.0.0 둀링 μ—…λ°μ΄νŠΈ μ‹œμž‘ ==="
kubectl set image deployment/$DEPLOYMENT \
  web=myapp/web:v2.0.0 -n $NAMESPACE

# μ‹€μ‹œκ°„ μ§„ν–‰ 상황 확인
echo "=== 배포 μ§„ν–‰ 상황 ==="
kubectl rollout status deployment/$DEPLOYMENT -n $NAMESPACE -w

# μ™„λ£Œ ν›„ μƒνƒœ 확인
echo "=== μ΅œμ’… μƒνƒœ ==="
kubectl get pods -n $NAMESPACE -l app=$DEPLOYMENT -o wide

# 배포 νžˆμŠ€ν† λ¦¬
echo "=== 배포 νžˆμŠ€ν† λ¦¬ ==="
kubectl rollout history deployment/$DEPLOYMENT -n $NAMESPACE

Practical Conversation

Junior Developer

"The service seems to drop briefly during deployments. Is it really a zero-downtime deployment?"

DevOps engineer

"Check the readinessProbe settings. That can happen if traffic arrives before the application is fully ready. Try increasing initialDelaySeconds a bit."

Junior Developer

"How do you decide the values for maxSurge and maxUnavailable?"

DevOps engineer

"It depends on traffic and spare resources. Our service has heavy traffic at peak time, so I set maxUnavailable conservatively to 1 and maxSurge to 2 to balance fast deployment and stability."

Junior Developer

"Is there a reason you chose Rolling Update over Blue-Green or Canary?"

DevOps engineer

"Resource efficiency. Blue-Green needs twice the infrastructure, and Canary has complex traffic routing setup. Rolling Update enables zero-downtime deployment at no extra cost."

Cautions

  • readinessProbe is required: If traffic is routed to a Pod that isn't ready, users see errors. Always configure appropriate health checks.
  • Graceful shutdown: Set terminationGracePeriodSeconds high enough to give existing connections time to close cleanly.
  • Version compatibility: During a rolling update, two versions run at the same time. Always verify API compatibility and data format compatibility.
  • Controlling deployment speed: Setting maxSurge too high can overload nodes due to resource shortage.
  • PodDisruptionBudget: Set a PDB to guarantee the minimum number of available Pods when multiple deployments run at the same time.

Learn More