Interview Prep/Kubernetes/Deployments and rollouts

How do you roll back a bad release and verify you are back on the previous version?

BeginnerScenarioDeployments and rollouts
Answer

Situation read → Production is showing errors right after a deploy and you need the last known-good version now.

What I'd do →

  1. kubectl rollout history deploy/web to see revisions
  2. kubectl rollout undo deploy/web (or --to-revision=3)
  3. kubectl rollout status deploy/web
  4. kubectl get deploy web -o jsonpath='{.spec.template.spec.containers[0].image}' to confirm the image
  5. Annotate the revision with the reason using kubectl annotate deploy/web kubernetes.io/change-cause="rollback to v1.4.2"

Why → Rollback re-applies the pod template of an older ReplicaSet, so it is fast and uses the same rolling strategy. Only the pod template is rolled back, not replicas or other fields.

Interview tip → Mention revisionHistoryLimit: if it is 0 there is nothing to roll back to.

All Kubernetes questions Roadmap: Kubernetes core

More on Deployments and rollouts