CrackOps
Interview PrepTracksLinuxAWS LabSoonInterview RoomSoon
Sign inStart free
CrackOps

Interview prep for the people who keep production up.

[email protected]
ProductInterview PrepTracksDashboardInterview Room
RolesDevOpsSREPlatformCloud
CompanyAboutContactPrivacyTerms
© CrackOps
Linux / Kubernetes / kubectl rollout

kubectl rollout

Watch, undo and restart Deployment rollouts

Intermediatekubernetesdeployrollback

kubectl rollout manages the rolling updates of Deployments, StatefulSets and DaemonSets: wait for one to finish (status), list revisions (history), roll back (undo), replace every pod gracefully (restart), and pause or resume changes.

Syntaxkubectl rollout (status | history | undo | restart | pause | resume) TYPE/NAME [--to-revision=N] [--timeout=5m] [-n NS]

Watch it run

CI built api:2.5.0. Update the Deployment and block until the rollout succeeds or fails, as a pipeline would.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 3
kubectl set image deploy/api api=123456789012.dkr.ecr.ap-south-1.amazonaws.com/api:2.5.0 -n prod

set image changes the container image in the pod template, which creates a new revision and starts a rolling update. (In GitOps you'd change the YAML instead.)

Anatomy of a command

$
commandkubectl

The Kubernetes CLI.

How it works

A Deployment never updates pods in place. Each distinct pod template gets its own ReplicaSet, named with a hash of the template and annotated with a revision number. When the template changes (new image, env, resources or a restartedAt annotation), the Deployment controller scales the new ReplicaSet up and the old one down in steps bounded by maxSurge (extra pods allowed, default 25%) and maxUnavailable (pods allowed missing, default 25%), and only counts a new pod once it's Ready for minReadySeconds. rollout status watches the Deployment's status fields (updatedReplicas, availableReplicas, conditions) and exits 0 when done or non-zero when the Progressing condition reports ProgressDeadlineExceeded (default 600s). undo copies an old ReplicaSet's template back into the Deployment, which triggers a normal rolling update. restart just sets a kubectl.kubernetes.io/restartedAt annotation on the template. Old ReplicaSets, kept at 0 replicas up to revisionHistoryLimit (default 10), are what make undo possible.

The Deployment shifts pods from the old ReplicaSet to a new one, one at a time, and only counts pods that pass readiness.

ownstrafficDeployment apireplicas: 3ReplicaSet oldapi-7f9c5d4b6ReplicaSet newapi-5b4d7c9f6Pods v2.4.13 runningPods v2.5.00 runningService apiready pods onlyClientsrequests
1/7
Steady state: revision 14

The Deployment owns one active ReplicaSet with 3 pods running api:2.4.1. The Service sends traffic to all three because they are Ready.

3/3Available
← → to step

Options you'll actually use

statusWait for the rollout to finish; non-zero exit if it fails
status --timeout=5mGive up waiting after a duration
history [--revision=N]List revisions, or show one revision's pod template
undo [--to-revision=N]Roll back to the previous or a specific revision
restartReplace all pods with a rolling update (same spec)
pause / resumeBatch several changes into one rollout
-w=falsestatus: print the current state once, don't wait

Common mistakes

Running kubectl apply in CI and calling it a successful deploy

apply returns before any pod starts; a broken image or failing probe is never noticed by the pipeline.

kubectl rollout status deploy/api --timeout=5m (non-zero exit fails the job)
kubectl rollout undo and moving on

Git still has the bad version; the next apply or GitOps sync redeploys it.

Undo to stop the bleeding, then revert the change in Git
Expecting rollout restart to pick up a new ConfigMap value automatically everywhere

Pods only see env from ConfigMaps at start; mounted files update eventually but the app may cache them. restart helps only for Deployments, STS and DS.

kubectl rollout restart deploy/api, or put a checksum of the config in a template annotation (Helm pattern)
Leaving CHANGE-CAUSE as <none>

History then can't tell you which revision held which release.

kubectl annotate deploy/api kubernetes.io/change-cause='release 2.5.0' after each deploy

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Write the commands to roll back the Deployment web in namespace shop to revision 7, after first checking which image revision 7 used.

  2. 2

    Write a CI step that fails the job if the Deployment api in prod hasn't finished rolling out within 3 minutes.

  3. 3

    Read this: 'Waiting for deployment "api" rollout to finish: 1 old replicas are pending termination...' repeated for 10 minutes. What do you check?

Related commands

kubectl applyCreate or update resources from YAML, declarativelykubectl scaleChange the replica count of a workloadhelmInstall, upgrade and roll back apps with Helm chartskubectl describeExplain an object's state, conditions and events
Previouskubectl scaleNextkubectl port-forward
Linux / Kubernetes / kubectl rollout

kubectl rollout

Watch, undo and restart Deployment rollouts

Intermediatekubernetesdeployrollback

kubectl rollout manages the rolling updates of Deployments, StatefulSets and DaemonSets: wait for one to finish (status), list revisions (history), roll back (undo), replace every pod gracefully (restart), and pause or resume changes.

Syntaxkubectl rollout (status | history | undo | restart | pause | resume) TYPE/NAME [--to-revision=N] [--timeout=5m] [-n NS]

Watch it run

CI built api:2.5.0. Update the Deployment and block until the rollout succeeds or fails, as a pipeline would.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 3
kubectl set image deploy/api api=123456789012.dkr.ecr.ap-south-1.amazonaws.com/api:2.5.0 -n prod

set image changes the container image in the pod template, which creates a new revision and starts a rolling update. (In GitOps you'd change the YAML instead.)

Anatomy of a command

$
commandkubectl

The Kubernetes CLI.

How it works

A Deployment never updates pods in place. Each distinct pod template gets its own ReplicaSet, named with a hash of the template and annotated with a revision number. When the template changes (new image, env, resources or a restartedAt annotation), the Deployment controller scales the new ReplicaSet up and the old one down in steps bounded by maxSurge (extra pods allowed, default 25%) and maxUnavailable (pods allowed missing, default 25%), and only counts a new pod once it's Ready for minReadySeconds. rollout status watches the Deployment's status fields (updatedReplicas, availableReplicas, conditions) and exits 0 when done or non-zero when the Progressing condition reports ProgressDeadlineExceeded (default 600s). undo copies an old ReplicaSet's template back into the Deployment, which triggers a normal rolling update. restart just sets a kubectl.kubernetes.io/restartedAt annotation on the template. Old ReplicaSets, kept at 0 replicas up to revisionHistoryLimit (default 10), are what make undo possible.

The Deployment shifts pods from the old ReplicaSet to a new one, one at a time, and only counts pods that pass readiness.

ownstrafficDeployment apireplicas: 3ReplicaSet oldapi-7f9c5d4b6ReplicaSet newapi-5b4d7c9f6Pods v2.4.13 runningPods v2.5.00 runningService apiready pods onlyClientsrequests
1/7
Steady state: revision 14

The Deployment owns one active ReplicaSet with 3 pods running api:2.4.1. The Service sends traffic to all three because they are Ready.

3/3Available
← → to step

Options you'll actually use

statusWait for the rollout to finish; non-zero exit if it fails
status --timeout=5mGive up waiting after a duration
history [--revision=N]List revisions, or show one revision's pod template
undo [--to-revision=N]Roll back to the previous or a specific revision
restartReplace all pods with a rolling update (same spec)
pause / resumeBatch several changes into one rollout
-w=falsestatus: print the current state once, don't wait

Common mistakes

Running kubectl apply in CI and calling it a successful deploy

apply returns before any pod starts; a broken image or failing probe is never noticed by the pipeline.

kubectl rollout status deploy/api --timeout=5m (non-zero exit fails the job)
kubectl rollout undo and moving on

Git still has the bad version; the next apply or GitOps sync redeploys it.

Undo to stop the bleeding, then revert the change in Git
Expecting rollout restart to pick up a new ConfigMap value automatically everywhere

Pods only see env from ConfigMaps at start; mounted files update eventually but the app may cache them. restart helps only for Deployments, STS and DS.

kubectl rollout restart deploy/api, or put a checksum of the config in a template annotation (Helm pattern)
Leaving CHANGE-CAUSE as <none>

History then can't tell you which revision held which release.

kubectl annotate deploy/api kubernetes.io/change-cause='release 2.5.0' after each deploy

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Write the commands to roll back the Deployment web in namespace shop to revision 7, after first checking which image revision 7 used.

  2. 2

    Write a CI step that fails the job if the Deployment api in prod hasn't finished rolling out within 3 minutes.

  3. 3

    Read this: 'Waiting for deployment "api" rollout to finish: 1 old replicas are pending termination...' repeated for 10 minutes. What do you check?

Related commands

kubectl applyCreate or update resources from YAML, declarativelykubectl scaleChange the replica count of a workloadhelmInstall, upgrade and roll back apps with Helm chartskubectl describeExplain an object's state, conditions and events
Previouskubectl scaleNextkubectl port-forward