StaffCoder
Kubernetes
15 modules · 60 challengesSign up
Module 9 · Rollouts & Rollbacks

History & Rollback

mediumRollout HistoryDeployment Rollback—No data yet

Problem statement

Namespace release-history runs payments-api on a hotfix that went out last night and made things worse. The manifest that built the previous version is gone - the branch it came from was deleted with the ticket - and the release note says only "hotfix". Nobody can say what the hotfix changed, and nobody can say what to go back to. The cluster can say both.

About this exercise

Every time a Deployment's pod template changes, the Deployment keeps the ReplicaSet for the old template and stamps it with a revision number. That stack of ReplicaSets is the Deployment's history: each entry is a complete pod template that once ran, held by the cluster whether or not anyone kept the YAML. So the record you need is not in the repository, it is in the namespace.

Two things read that record. The history listing shows the revision numbers and, beside each, its change cause - the value of the annotation kubernetes.io/change-cause on that revision. The cause is not automatic: a revision only carries one because someone put it there, and a history of <none> is exactly what an undocumented release leaves behind. Asking for a single revision instead prints that revision's whole pod template - images, commands, environment - which is how a lost manifest is recovered.

Going back is the other half. A rollback re-applies an earlier revision's template as the newest revision: history moves forward, never backward, so a rollback is itself a release and can be rolled back in turn. Because the earlier ReplicaSet already matches that template exactly, the Deployment re-uses it rather than building a new one - which is why the revision number you rolled back to disappears from the listing and reappears at the top with a new number. You can go back to whatever the last release was, or name the revision you want.

One trap comes with change causes: the annotation lives on the Deployment, and the Deployment copies its annotations onto the revision that is current at that moment. Record a cause at the wrong point and you have relabelled a revision that shipped weeks ago.

kubectl rollout --help is the reference.

How this project is graded

The grader reads the live Deployment, every ReplicaSet it owns, and the revision number and change cause each one carries. Revision numbers move as you work, so the listings you were asked to save are graded as the record you took at that moment, and the final state is graded against the cluster. The namespace is re-seeded only when the Deployment is missing, so the history you build is yours to keep.

What you will build

Everything lives in namespace release-history, deployment payments-api, container api.

Files in answers/:

history.txt        the revision listing exactly as it stands before you change
                   anything - both revisions and what each records
revision-1.txt     revision 1's own detail: the full pod template of the build
                   whose manifest was lost
history-final.txt  the revision listing once every step below is done

The releases, in this order, each landing as a revision that carries its own change cause:

1. back to the previous revision            cause: rollback to pinned build 41
2. image alpine:3.20, env RELEASE=build-78  cause: promote build 78
3. back to revision 2 specifically          cause: restore hotfix build 77

Recording a cause must not rewrite the cause already sitting on an earlier revision, and each of the three ReplicaSets must end up holding one of the three causes above. When you are done the pods must be serving the template that revision 2 held - nginx:alpine with RELEASE=hotfix-77 - with all 3 replicas ready.

Step 1 - read the record nobody wrote

Save the revision listing as it stands now, and recover the pod template of revision 1 in full.

history_listing_captured_before_anything_changed and revision_detail_recovered_the_lost_template should pass

Step 2 - undo the hotfix

Return the Deployment to the revision before the current one, and record its change cause.

undo_restored_the_previous_template_under_a_new_revision should pass

Step 3 - ship the next build, documented this time

Release the new image and marker together with the cause above.

every_revision_carries_its_own_change_cause should pass

Step 4 - go back to a revision by name

Return to revision 2 specifically, record its cause, and save the finished listing.

rollback_to_a_named_revision_restored_exactly_that_template and final_history_lists_every_revision_with_its_cause should pass

When every test passes

You have:

  • A lost manifest recovered from the cluster instead of from a deleted branch
  • A release history where every revision says what it was for
  • The previous version back in service, and the proof that a rollback is just another release
  • A named revision restored byte-for-byte, re-using the ReplicaSet that already held it

You do not have yet:

  • Any control over a release while it is happening. Batching several edits into one rollout, and getting a verdict when a rollout never finishes at all, is the next exercise.

Verify

Click Test after every step.

More in Rollouts & Rollbacks

See the module
Rolling UpdatesReplace an all-at-once release with a rolling one: declare surge and unavailable bounds, roll a new image through the Deployment and prove from sampled counts that the replacement stayed inside them.—No data yetmediumPause, Resume & Failed RolloutsBatch several template edits into one rollout with pause and resume, then make a stuck release report itself against a progress deadline and recover it by rolling back.—No data yetmediumRelease Train DisciplineRun three releases of a web tier end to end: a bounded rolling update, a batched pause-and-resume release, and a broken one that must report itself against the progress deadline and be reversed, with a change-cause audit trail throughout.—No data yetmedium

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.