Opscraft
Deployment strategies · Lesson 2 of 10 · 5 min read

Recreate and rolling updates

Recreate

All old instances stop, then new ones start.

Enlarge diagramv1 servingdowntimev2 servingtime →
Figure 1. Recreate: everything old stops before anything new starts, so there is a gap with nothing serving.
Swipe sideways to see all of it, or tap to open it full screen.
  • Pro: simplest; versions never run concurrently (good when they can't — e.g. an app that takes an exclusive lock or runs incompatible migrations on startup).
  • Con: downtime between old stopping and new being ready; rollback also means downtime.
spec:
  strategy:
    type: Recreate

Use it for dev environments, singleton workers, or when brief downtime is acceptable and coexistence is impossible.

Rolling update — how Kubernetes actually does it

RollingUpdate is the default for Deployments. Changing the pod template (new image, env, config) creates a new ReplicaSet; the Deployment controller scales the new one up and the old one down in steps, governed by two knobs:

  • maxSurge — how many pods above replicas may exist during the rollout (number or %, default 25%, rounded up).
  • maxUnavailable — how many pods below replicas may be unavailable (default 25%, rounded down).

Worked example, replicas: 4:

Enlarge diagramstep 0v1v1v1v1step 1v1v1v1v1v2step 2v1v1v1v2step 3v1v1v1v2v2step 4v1v1v2v2step 5v1v2v2v2step 6v2v2v2v2Never fewer than 4 ready pods; at most 5 at once. Both versions serve traffic in between.
Figure 2. A rolling update with replicas 4, maxSurge 1, maxUnavailable 0: add one new pod, wait until it is ready, remove one old pod, repeat.
Swipe sideways to see all of it, or tap to open it full screen.
Setting Behaviour
defaults (25%/25%) surge 1, unavailable 1: at least 3 available, at most 5 total
maxSurge: 1, maxUnavailable: 0 Start one new pod, wait until it's available, remove one old — capacity never drops; slowest, safest
maxSurge: 0, maxUnavailable: 1 Remove one old first, then add new — no extra capacity needed, but capacity dips
maxSurge: 100%, maxUnavailable: 0 Bring up a full new set, then remove the old — fast, blue-green-like capacity cost

Both can't be zero.

Other fields that matter:

spec:
  replicas: 6
  minReadySeconds: 15            # a new pod must stay Ready this long before it counts as "available"
  progressDeadlineSeconds: 600   # no progress for 10 min → condition Progressing=False (ProgressDeadlineExceeded)
  revisionHistoryLimit: 10       # old ReplicaSets kept for rollback
  strategy:
    type: RollingUpdate
    rollingUpdate: { maxSurge: 25%, maxUnavailable: 0 }
  • minReadySeconds catches pods that pass readiness briefly then crash.
  • progressDeadlineSeconds doesn't roll back by itself — it marks the rollout failed so kubectl rollout status exits non-zero and your pipeline/Flux health checks can react.
  • A failing readiness probe stalls the rollout: new pods never become available, old pods aren't removed, users keep being served by the old version. That's the safety net working.
kubectl rollout status deploy/orders --timeout=5m    # wait; non-zero exit on failure
kubectl rollout history deploy/orders
kubectl rollout history deploy/orders --revision=7
kubectl rollout undo deploy/orders                    # previous revision
kubectl rollout undo deploy/orders --to-revision=5
kubectl rollout pause deploy/orders                   # batch several changes, or freeze mid-rollout
kubectl rollout resume deploy/orders
kubectl rollout restart deploy/orders                 # re-create pods with the same spec

Set kubernetes.io/change-cause annotations (or rely on Git history with GitOps) so revisions are understandable.

Watch out: with Flux/GitOps, kubectl rollout undo is temporary — Flux reconciles the Deployment back to what's in Git. Roll back by reverting the commit (or suspend the Kustomization during an emergency, then revert).

Rolling updates outside Kubernetes

  • EC2 Auto Scaling — Instance Refresh: replace instances in batches with a new launch template version; MinHealthyPercentage, warm-up time, checkpoints, and automatic rollback on failure.
  • ECS: minimumHealthyPercent / maximumPercent (the same idea as maxUnavailable/maxSurge), with the deployment circuit breaker to roll back automatically when tasks fail to stabilise.
  • Elastic Beanstalk / CodeDeploy in-place: rolling with a batch size.

Pros of rolling: no duplicate environment, gradual. Cons: both versions serve traffic simultaneously (they must be compatible), and rollback is another rolling update, not instant.