M2-S3 — Upgrade and roll back
Section titled “M2-S3 — Upgrade and roll back”| Module | M2 — Install, upgrade and roll back |
| After this session you can | Run an upgrade the safe way, recover from a failed one with a rollback, and decide what to do when the database has already moved on. |
| Time | Facilitated: 45 min · On your own: 45 min |
| Before you start | M2-S2: the nw release installed and your written smoke test. |
| Go deeper | Deployment: 1.10 upgrade checklist · Runbooks: migration recovery |
◆ Orientation (1 min) — Upgrades are where releases break
Section titled “◆ Orientation (1 min) — Upgrades are where releases break”Installing happens once. Upgrading happens every few weeks, to a release full of real data, often in a short maintenance window. Most production incidents an operator causes are upgrades done without a backup, a render or a way back. This session gives you all three, and the judgment for the one case where Helm cannot take you back.
▤ Concept (4 min) — What an upgrade changes, and what a rollback does not
Section titled “▤ Concept (4 min) — What an upgrade changes, and what a rollback does not”An upgrade, step by step
Section titled “An upgrade, step by step”helm upgrade renders the chart with the values you give it, compares the result with the release’s
current revision, and applies the difference. Around that, the chart’s hooks run again: the image
pull Secret and the bus set-up Job before (pre-upgrade), and the migration Job after
(post-upgrade), under a new name for each revision (nw-osos-migration-2, -3 …). Workloads whose
configuration changed roll, because each Deployment carries a checksum of the ConfigMaps and Secrets
it reads. Workloads with no change keep running untouched.
So every upgrade, even one that only changes a value, runs the migration. On a new application version the migration may change data in MongoDB, and many of those changes cannot be reversed in place. That is why the first step of every upgrade is a backup.
What helm rollback does
Section titled “What helm rollback does”helm rollback nw 2 re-applies revision 2’s manifests and values as a new revision. Workloads go
back to revision 2’s images and configuration. What it does not do:
- It does not run the migration. The migration is a
post-installandpost-upgradehook, not a rollback hook. - It does not undo a migration that already ran. The platform never runs a migration’s reverse step automatically. An older application finding a database “ahead” of it only logs a warning naming the migrations involved, and carries on.
A rollback is therefore safe and complete when the upgrade changed configuration or images only, or failed before its migration changed data. When a migration has already changed data, the way back is a restore from the backup you took first.
flowchart TD
F["The upgrade failed or misbehaves"] --> Q{"Did its migration<br/>change data?"}
Q -->|"No: config or image only,<br/>or failed before migrating"| R["helm rollback to the last good revision"]
Q -->|"Yes"| P{"Is a fixed version<br/>available now?"}
P -->|"Yes"| U["Roll forward: upgrade to the fix"]
P -->|"No, and data is wrong"| B["Restore the backup,<br/>then roll back"]
What to notice: the question that decides is about the data, not the pods. Read the migration Job’s log before you choose.
A failed upgrade
Section titled “A failed upgrade”If a workload never becomes ready within --timeout, or the migration Job fails, Helm marks the
revision failed. The workloads that already rolled stay on the new version; the release does not
undo itself. You then read why (pod events, the migration log), and either fix and upgrade again (the
migration resumes at the first script that did not finish) or roll back. Helm’s --atomic flag rolls
back automatically on failure; avoid it for Osos upgrades, because it can roll the workloads
back after a migration has already changed data, and hides the moment you should have decided.
The upgrade routine
Section titled “The upgrade routine”- Read the vendor’s upgrade notes for every version between yours and the target. They list
values that became required or were removed, and switches with an order (for example, between 1.8
and 1.10:
core.mongoUrlTemplatebecame mandatory andidentity.config.recoveryCodePeppermust be set). - Back up MongoDB.
- Render the new version with your values and compare it with what runs:
helm get manifestfor the current revision,helm templatefor the new one, thendiff. - Upgrade with
--waitand a generous--timeout. - Run the smoke test, then read the migration Job’s log.
- Record the old and new revision numbers, and keep the backup until the release has run cleanly for a full business cycle.
Renewing or replacing the license
Section titled “Renewing or replacing the license”Your vendor holds the expiry date, so ask for renewal before it. A renewal with no new values needs
no change. New values go in the same way you installed them: replace your own Secret’s contents and
restart the gateway (the chart does not render a Secret you manage), or change the values and run
helm upgrade, which restarts it. Then run the smoke test again. The
job aid lists the commands and what to do when
the license is refused.
⛏ Lab (32 min) — One good upgrade, one bad one, one rollback
Section titled “⛏ Lab (32 min) — One good upgrade, one bad one, one rollback”Goal. Revision 2 applied cleanly, revision 3 failed on purpose, and the release rolled back to revision 2 and proven by the smoke test.
Before you start. values set as in M2-S1. The smoke test from M2-S2.
Back up first
-
Take a MongoDB archive and copy it out of the pod:
Terminal window kubectl -n datastores exec mongo-0 -- mongodump --archive=/tmp/pre-upgrade.gz --gzipkubectl -n datastores cp mongo-0:/tmp/pre-upgrade.gz ./pre-upgrade.gz(M4-S3 turns this into a full backup and restore procedure.)
A good upgrade
-
In
nw-values.yaml, addttlSecondsAfterFinished: 7200undermigration:(keep migration Jobs for two hours instead of 24). -
See what will change before it changes:
Terminal window helm get manifest nw -n northwind > current.yamlhelm template nw ./osos -n northwind $values > next.yamldiff current.yaml next.yamlThe change itself is in the migration Job. The diff also lists the chart’s hook resources (the Jobs and some Secrets) as new, because
helm get manifestleaves hooks out, and new random values in the identity and storage Secrets, because an offline render cannot read the live ones. Neither is a change the upgrade makes. -
Upgrade:
helm upgrade nw ./osos -n northwind $values --wait --timeout 20m. -
Read the history:
helm history nw -n northwind. Revision 1 issuperseded, revision 2deployed.kubectl -n northwind get jobsshowsnw-osos-migration-2Complete; no workload restarted (kubectl -n northwind get podsshows the same ages as before).
A bad upgrade
-
Upgrade with an image tag that does not exist, and a short timeout:
Terminal window helm upgrade nw ./osos -n northwind $values \--set web.image.tag=0.0.0-does-not-exist --wait --timeout 3m -
Watch it fail. After three minutes Helm reports an error;
helm historyshows revision 3failed.kubectl -n northwind get podsshows a new web pod inImagePullBackOff, while the old web pod still serves (the rollout never completed). -
Decide: did a migration change data in revision 3? Check:
kubectl -n northwind get jobs. There is nonw-osos-migration-3, because Helm stopped before its post-upgrade hooks. So a rollback is complete.
Roll back
helm rollback nw 2 -n northwind --wait --timeout 10m.helm history nw -n northwindshows revision 4deployed, described as a rollback to 2. The bad web pod is gone.- Run your smoke test from M2-S2, product part only: sign in as
nwoperatorand open Administration. - Add the revisions to
inventory.md: what each one changed and its status.
Check.
-
pre-upgrade.gzexists in your working folder and is larger than a few kilobytes. - Revision 2 is the TTL change, applied without restarting any workload.
- Revision 3 is
failed, and you can say why fromkubectl describeon the web pod. - You checked for a migration Job before rolling back.
- Revision 4 is
deployedas a rollback to 2, and no pod is inImagePullBackOff. - The operator can still sign in and open Administration.
Pass condition. All six checks hold, and your inventory records revisions 1 to 4.
If something goes wrong
| What you see | What to do |
|---|---|
mongodump is not found | The mongo:7.0 image includes it; check you ran it in mongo-0 in datastores. |
| Step 3’s diff shows many changes | Some charts generate random values on each render; if a key appears that you did not set, note it. If whole Deployments differ, check you used the same values files as the install. |
| Step 4 restarts pods | A value other than the TTL changed. Compare helm get values nw -n northwind with your files. |
| Step 6 succeeds | The tag may exist in your registry. Use an obviously wrong one, such as 0.0.0-does-not-exist. |
helm rollback waits forever | A pod of revision 2 cannot start; kubectl describe it. The release is still usable while you look. |
You see nw-osos-migration-3 | Helm reached the hooks; read its log before rolling back, and follow the decision diagram. |
Model answer
helm history nw -n northwind after the lab:
| Revision | Status | Description |
|---|---|---|
| 1 | superseded | Install complete |
| 2 | superseded | Upgrade complete |
| 3 | failed | Upgrade “nw” failed: … context deadline exceeded |
| 4 | deployed | Rollback to 2 |
kubectl describe pod on the failed web pod shows Failed to pull image …:0.0.0-does-not-exist and
ErrImagePull, then ImagePullBackOff. No migration ran in revision 3, so the rollback restored the
release completely: the data never changed. Had nw-osos-migration-3 existed and finished, you would
have read its log to see whether it changed data before choosing between a rollback and a restore.
◇ Worked scenario (2 min) — The Friday upgrade
Section titled “◇ Worked scenario (2 min) — The Friday upgrade”Northwind upgrades production from app version 1.10.0 to a patch release on Friday evening. The migration Job completes. On Monday, finance reports that a list of expense claims sorts wrongly.
Decide: roll back?
First, find out what the migration did. Its log lists the scripts it applied, and the vendor’s notes say what each changed. Suppose one script added a new index and another rewrote a date field into a new format. A rollback would bring back the old application on data it no longer expects: the platform would only log a warning that the database is ahead, and the old code would read dates in the wrong format. That is worse than the sorting bug.
Decide: restore Friday’s backup?
A restore brings back Friday evening’s data. Everything entered since (three days of claims and approvals) would be lost or have to be re-entered. For a sorting bug, that cost is far too high.
The choice. Roll forward: report the bug to the vendor with the migration log and the affected list, ask for the fixed patch, and keep the backup until it is applied. A restore is for data that is wrong or lost; a rollback is for an upgrade that changed configuration or images only. Neither is a shortcut for a bug in a new version that already moved the data.
✓ Practice (5 min) — Check your understanding
Section titled “✓ Practice (5 min) — Check your understanding”An upgrade to a new application version completed, including its migration. You roll back with
helm rollback. What state is the database in?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
An upgrade fails because the migration Job failed halfway through a script. You found and fixed the cause. What do you do?
Check your answer
The correct answer is A. Open the explanation under each option to see why.
A colleague proposes helm upgrade --atomic for every production upgrade “so failures clean
themselves up”. What is the risk?
Check your answer
The correct answer is C. Open the explanation under each option to see why.
Put the upgrade routine in order.
Check your answer
The correct order is B → C → E → A → D. Open the explanation under each item to see why it sits where it does.
↺ Recap (1 min) — After Module 2 you can
Section titled “↺ Recap (1 min) — After Module 2 you can”After this module you can write a release’s values and secrets safely, install it and prove it with a smoke test, upgrade it the safe way, roll it back, and decide between rolling back, rolling forward and restoring when the data has already moved.
Next. Module 3 opens the release to its users: the web addresses of the tenant and its spaces, and the gateway that every API request passes through.