How to Do a Kubernetes Rolling Update

A Kubernetes rolling update lets you ship a new container image version without taking the service down. Bump the image tag in the Deployment spec, apply it, and Kubernetes replaces pods one at a time while keeping the rest live.

Kubernetes Engineerkuberneteskubectldeployments

How Kubernetes rolling updates work

When you change a Deployment's pod template (usually the container image tag), Kubernetes creates a new ReplicaSet and migrates traffic to it gradually. The default RollingUpdate strategy keeps the service up throughout:

For a 3-replica Deployment that means at most 1 pod goes down before a replacement is Ready - so at least 2 pods are always serving.

Step 1: check the current image

kubectl get deploy api -o jsonpath='{.spec.template.spec.containers[0].image}{"\n"}'

This confirms which image is running before you touch anything.

Step 2: bump the image tag in the Deployment manifest

Edit deployment.yaml and update the image field:

spec:
  template:
    spec:
      containers:
        - name: api
          image: nginx:1.27-alpine   # was nginx:1.26-alpine

Then apply:

kubectl apply -f deployment.yaml

Step 3: watch the rollout

kubectl rollout status deploy/api

Output tracks each pod as it is replaced:

Waiting for deployment "api" rollout to finish: 1 out of 3 new replicas have been updated...
Waiting for deployment "api" rollout to finish: 2 out of 3 new replicas have been updated...
deployment "api" successfully rolled out

The command exits 0 on success and non-zero if the rollout stalls, making it safe to use in a CI pipeline step.

If something goes wrong: roll back

kubectl rollout undo deploy/api

This reverts to the previous ReplicaSet in seconds - no manifest editing required. Check history with kubectl rollout history deploy/api.

What to add before production

Want to try it hands-on? HeyDevJob gives you this exact setup in a live cloud workspace in your browser - edit it, run it, and see it work. Free, nothing to install.

Try it in a workspace →

What you'll practice

FAQ

How do I update the image in a Kubernetes Deployment?

Edit the image field in the Deployment's pod template spec (or run kubectl set image deploy/<name> <container>=<new-image>), then apply the change. Kubernetes triggers a rolling update automatically.

What does kubectl rollout status do?

It streams live progress of a Deployment rollout, showing how many replicas have been updated. It exits 0 when the rollout completes successfully and non-zero if it stalls or fails - useful in CI pipelines.

How do I roll back a Kubernetes Deployment?

Run kubectl rollout undo deploy/<name>. Kubernetes reverts to the previous ReplicaSet immediately. Use kubectl rollout history deploy/<name> to see past revisions and --to-revision=N to target a specific one.

What is a Kubernetes rolling update?

A rolling update replaces a Deployment's pods gradually - it starts new-version pods, waits until they are ready, then terminates old ones, so the app stays available with zero dropped requests during the release.

Keep learning

Fix a Kubernetes CrashLoopBackOffKubernetes projectHeal a Kubernetes Service With No EndpointsKubernetes projectFix a Kubernetes ImagePullBackOffKubernetes projectKubernetes roadmapStep by step to hiredKubernetes interview questionsSTAR answersAll Kubernetes projectsProjects hub

Learn it by doing. Open this in a live cloud workspace, make the change yourself, and keep a record of the work you can share.

Open the workspace →