Skip to content
ModuleM2 — Install, upgrade and roll back
After this session you canRun 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.
TimeFacilitated: 45 min · On your own: 45 min
Before you startM2-S2: the nw release installed and your written smoke test.
Go deeperDeployment: 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”

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.

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-install and post-upgrade hook, 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.

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.

  1. 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.mongoUrlTemplate became mandatory and identity.config.recoveryCodePepper must be set).
  2. Back up MongoDB.
  3. Render the new version with your values and compare it with what runs: helm get manifest for the current revision, helm template for the new one, then diff.
  4. Upgrade with --wait and a generous --timeout.
  5. Run the smoke test, then read the migration Job’s log.
  6. Record the old and new revision numbers, and keep the backup until the release has run cleanly for a full business cycle.

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

  1. 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 --gzip
    kubectl -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

  1. In nw-values.yaml, add ttlSecondsAfterFinished: 7200 under migration: (keep migration Jobs for two hours instead of 24).

  2. See what will change before it changes:

    Terminal window
    helm get manifest nw -n northwind > current.yaml
    helm template nw ./osos -n northwind $values > next.yaml
    diff current.yaml next.yaml

    The 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 manifest leaves 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.

  3. Upgrade: helm upgrade nw ./osos -n northwind $values --wait --timeout 20m.

  4. Read the history: helm history nw -n northwind. Revision 1 is superseded, revision 2 deployed. kubectl -n northwind get jobs shows nw-osos-migration-2 Complete; no workload restarted (kubectl -n northwind get pods shows the same ages as before).

A bad upgrade

  1. 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
  2. Watch it fail. After three minutes Helm reports an error; helm history shows revision 3 failed. kubectl -n northwind get pods shows a new web pod in ImagePullBackOff, while the old web pod still serves (the rollout never completed).

  3. Decide: did a migration change data in revision 3? Check: kubectl -n northwind get jobs. There is no nw-osos-migration-3, because Helm stopped before its post-upgrade hooks. So a rollback is complete.

Roll back

  1. helm rollback nw 2 -n northwind --wait --timeout 10m.
  2. helm history nw -n northwind shows revision 4 deployed, described as a rollback to 2. The bad web pod is gone.
  3. Run your smoke test from M2-S2, product part only: sign in as nwoperator and open Administration.
  4. Add the revisions to inventory.md: what each one changed and its status.

Check.

  • pre-upgrade.gz exists 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 from kubectl describe on the web pod.
  • You checked for a migration Job before rolling back.
  • Revision 4 is deployed as a rollback to 2, and no pod is in ImagePullBackOff.
  • 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 seeWhat to do
mongodump is not foundThe mongo:7.0 image includes it; check you ran it in mongo-0 in datastores.
Step 3’s diff shows many changesSome 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 podsA value other than the TTL changed. Compare helm get values nw -n northwind with your files.
Step 6 succeedsThe tag may exist in your registry. Use an obviously wrong one, such as 0.0.0-does-not-exist.
helm rollback waits foreverA pod of revision 2 cannot start; kubectl describe it. The release is still usable while you look.
You see nw-osos-migration-3Helm reached the hooks; read its log before rolling back, and follow the decision diagram.
Model answer

helm history nw -n northwind after the lab:

RevisionStatusDescription
1supersededInstall complete
2supersededUpgrade complete
3failedUpgrade “nw” failed: … context deadline exceeded
4deployedRollback 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”
PracticeChoose one answer.

An upgrade to a new application version completed, including its migration. You roll back with helm rollback. What state is the database in?

  1. Explanation for A

    ✗ Incorrect

    Not this one: the platform never reverses a migration automatically. See What helm rollback does.

  2. Explanation for B

    ✓ Correct

    Correct: a rollback restores workloads and values, never data. Restoring data needs the backup. See What helm rollback does.

  3. Explanation for C

    ✗ Incorrect

    Not this one: the migration runs on install and upgrade, not on rollback. See What helm rollback does.

Check your answer

The correct answer is B. Open the explanation under each option to see why.

PracticeChoose one answer.

An upgrade fails because the migration Job failed halfway through a script. You found and fixed the cause. What do you do?

  1. Explanation for A

    ✓ Correct

    Correct: completed scripts are recorded, so the re-run picks up where it stopped. See A failed upgrade.

  2. Explanation for B

    ✗ Incorrect

    Not this one: uninstalling does not reset the database, and loses the release history. See A failed upgrade.

  3. Explanation for C

    ✗ Incorrect

    Not this one: scripts that already ran would run twice on real data. See A failed upgrade.

Check your answer

The correct answer is A. Open the explanation under each option to see why.

PracticeChoose one answer.

A colleague proposes helm upgrade --atomic for every production upgrade “so failures clean themselves up”. What is the risk?

  1. Explanation for A

    ✗ Incorrect

    Not this one: the hooks still run; the risk is what happens after a failure. See A failed upgrade.

  2. Explanation for B

    ✗ Incorrect

    Not this one: it rolls back to the previous revision, it does not delete. See A failed upgrade.

  3. Explanation for C

    ✓ Correct

    Correct: the automatic rollback cannot see the data. Decide yourself, with the migration log in hand. See A failed upgrade.

Check your answer

The correct answer is C. Open the explanation under each option to see why.

PracticePut the items in the right order.

Put the upgrade routine in order.

  1. Explanation for A

    Belongs in position 4 of 5

    Fourth, once you know exactly what will change. See The upgrade routine.

  2. Explanation for B

    Belongs in position 1 of 5

    First, because they tell you which values to add or change before anything else. See The upgrade routine.

  3. Explanation for C

    Belongs in position 2 of 5

    Second, before anything can change data, so a restore is always possible. See The upgrade routine.

  4. Explanation for D

    Belongs in position 5 of 5

    Last, because only a working product and a clean migration prove the upgrade. See The upgrade routine.

  5. Explanation for E

    Belongs in position 3 of 5

    Third, to see every change and catch render-time failures before the cluster is touched. See The upgrade routine.

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.