Recover from a bad change
Meet the three ways a deployment goes wrong, a render that Wardn holds, a change made by hand in the cluster, and a release that applied and should not have, and fix each with the right tool.
When something goes wrong with a deployment, the cause is one of three, and each has its own tool. A commit renders to almost nothing, and Wardn holds the snapshot before it reaches the cluster. Someone changes the cluster by hand, and the cluster drifts from git. A release applies cleanly and is simply wrong, and you restore the snapshot before it. This tutorial causes each on purpose, on a deployment you can afford to break, and fixes it.
It takes about 45 minutes and ends with:
- a held snapshot that you read and discarded, with the cluster untouched;
- drift that you saw as a diff and reverted;
- a restore with a preflight that warned about a rotated secret, and a deployment back on its last good snapshot.
You need the deployment from Deploy your first app: the app web with its ConfigMap, Deployment and Service in deploy/web, and the deployment web-dev on a cluster called dev, namespace shop, following main. The steps below use kubectl --context kind-dev; use your own context. You need to be the Owner, or to hold snapshot:signoff, drift:revert, deployment:rollback and deployment:manage on the deployment. For the API tabs set WARDN_API_URL and WARDN_TOKEN and define:
api() { curl -fsS -H "Authorization: Bearer $WARDN_TOKEN" -H 'Content-Type: application/json' "$@"; }and keep the deployment's id in DEPLOYMENT_ID.
Part 1: a snapshot that Wardn holds
A commit can quietly empty a deployment: a directory renamed, a template condition flipped. If Wardn applied a snapshot with pruning on, it would delete real workloads. So the render guard compares every new snapshot with the newest approved one and holds it when it has no objects, or lacks more than half of them. Held snapshots has the rules.
Move the manifests
In your repository, rename the directory the app reads, commit and push:
git mv deploy/web deploy/app
git commit -m "Reorganize deploy directory"
git push origin mainThe app's Path is still deploy/web, so a plain-manifests app finds no files and renders nothing. A mistake like this is exactly what the guard is for.
Find the held snapshot
Within a minute, open Deployments › web-dev › Snapshots. The newest entry is marked Held for review. Open it. The panel at the top gives the reason, The render has no objects, and the counts: the current snapshot holds 3 objects, this one 0, so 3 would be removed.
api "$WARDN_API_URL/api/v1/deployments/$DEPLOYMENT_ID/snapshots" \
| jq '.items[] | select(.reviewState=="held") | {id, contentId, commit}'
SNAPSHOT_ID=... # the id printed aboveCheck that nothing happened to the cluster:
kubectl --context kind-dev -n shop get deploy,svc,cmAll three objects are still there and the deployment still shows Healthy. A held snapshot is stored and never applied, and the deployment keeps running its current snapshot. Audit › Activity has a snapshot.held entry with the commit and the counts.
Discard it, and fix git
Discard refuses this snapshot for good. Release would approve it and apply an empty deployment, which is only right when you really meant to remove everything.
On the held snapshot's panel, choose Discard. The panel then shows who decided and when. Without snapshot:signoff both buttons are disabled with the hint Needs the snapshot:signoff permission.
Then put the directory back and push:
git revert --no-edit HEAD
git push origin mainThe next snapshot is compared with the newest approved one, not with the held one, so it passes and applies as a no-op. A discarded snapshot cannot be restored later.
Part 2: a change made by hand
During an incident someone edits production directly. The cluster now says something git does not. Wardn does not undo it unless you ask, but it shows it, as drift.
Change the cluster
kubectl --context kind-dev -n shop patch cm web-config \
--type merge -p '{"data":{"GREETING":"edited by hand"}}'See the drift
The operator compares the live objects with the snapshot it last applied after each apply and on a schedule (every five minutes by default), then confirms a difference with a second look. Within a few minutes open Deployments › web-dev › Drift. What drifted lists ConfigMap/web-config and the field /data/GREETING, with the value the snapshot sets (hello from git) and the value the cluster has (edited by hand). The Live diff tab shows the same as a diff of the whole object (Compare snapshots).
api "$WARDN_API_URL/api/v1/deployments/$DEPLOYMENT_ID/drift"Only fields Wardn owns count. The replica count an autoscaler sets, a sidecar that a webhook injects and the defaults the API server adds are not drift.
Choose what to do
Each drifted object has Your choice: Adopt, Revert or Ignore field.
| Choice | Use it when | Effect |
|---|---|---|
| Revert | The cluster is wrong | Applies the running snapshot again, so git wins |
| Adopt | The cluster is right and git is wrong | Records the exact JSON patch to take to git. Wardn does not push it for you |
| Ignore field | Something else is meant to own this field | A standing rule: this field is never reported again |
Someone edited a greeting by hand, which git should win. Choose Revert, then apply your choice and confirm ("Apply your choices?").
api -X POST "$WARDN_API_URL/api/v1/deployments/$DEPLOYMENT_ID/drift/revert" -d '{}'
kubectl --context kind-dev -n shop get cm web-config -o jsonpath='{.data.GREETING}'The command prints hello from git. Revert needs drift:revert. To have Wardn do this by itself, set the deployment's Drift section to Revert after a delay, which leaves time to adopt a change someone made on purpose (Let Wardn revert drift).
Part 3: a release that was wrong
The third case is the common one. The change renders, applies and passes every check, and is still wrong. Here it scales the deployment to zero, which Kubernetes treats as healthy: the rollout is complete, it just serves nobody. The tool is a restore.
Give the restore something to check
A secret that a deployment depends on can change between a release and its rollback. Wardn watches secrets by reference, never by value (Secret references). Make one in the cluster and declare it, so the preflight has something to compare:
kubectl --context kind-dev -n shop create secret generic shop-db --from-literal=password=one
api -X PUT "$WARDN_API_URL/api/v1/deployments/$DEPLOYMENT_ID/secret-refs" -d '{
"refs": [{"name": "db-password", "source": "k8s", "locator": "shop-db", "key": "password"}]
}'
api -X POST "$WARDN_API_URL/api/v1/deployments/$DEPLOYMENT_ID/sync"Declaring the reference does not push it to the operator; the sync does (When they are checked). The reading taken while this snapshot runs becomes its baseline. Wait until the reference shows present:
api "$WARDN_API_URL/api/v1/deployments/$DEPLOYMENT_ID/secret-refs" | jq '.refs[] | {name, status, fingerprint}'The web app does not edit references yet, so this step is API-only. Note the snapshot that is running now: this is the one you will come back to.
GOOD=$(api "$WARDN_API_URL/api/v1/deployments/$DEPLOYMENT_ID/state" | jq -r .snapshotId)Ship the bad release
spec:
replicas: 0data:
GREETING: hello from the wrong releaseCommit and push to main. Within a minute the new snapshot applies and the deployment shows Healthy. No guard fired: the snapshot has the same three objects. Nobody is served:
kubectl --context kind-dev -n shop get deploy webChange the secret behind it
A rollback that finds the world changed is the case the preflight exists for. Rotate the secret, then apply again so the operator checks it:
kubectl --context kind-dev -n shop create secret generic shop-db \
--from-literal=password=two --dry-run=client -o yaml | kubectl --context kind-dev apply -f -
api -X POST "$WARDN_API_URL/api/v1/deployments/$DEPLOYMENT_ID/sync"Run the secret-refs call again until the fingerprint differs from before. The fingerprint is a keyed hash made in the cluster: Wardn can see that the value moved without ever seeing it.
Restore the good snapshot
Open Deployments › web-dev › Snapshots and open the snapshot you noted. Choose Back to an earlier snapshot. The dialog shows, before anything happens:
- What changes: 1 of 1 apps, with the commits.
- Where it runs: the
devcluster. - Before you restore: the checks. Under Secrets match one reads Secret changed since this snapshot ran, a warning. The cluster, the images and the target pass.
A warning does not stop a restore: it tells you the database password is not the one this snapshot ran with, so read it before you go on. Write a Why restore, for example "zero replicas in the last release", and choose Restore 1 app on dev.
The restore applies through the normal path, with the same waves and prune limit. Check:
kubectl --context kind-dev -n shop get deploy web
kubectl --context kind-dev -n shop get cm web-config -o jsonpath='{.data.GREETING}'Two replicas, and hello from git. In the history the new snapshot is marked Rolled back, and Audit › Activity has deployment.restore with your reason and the number of findings.
Fix the branch, or it moves forward again
A restore does not turn off sync on push. main still holds the bad commit, so the next push would render it and apply it again. Revert it:
git revert --no-edit HEAD
git push origin mainIf you need time before you can fix git, set the deployment to Observe only in its settings first.
When the preflight blocks
A warning is information. A blocking finding stops the restore. To see one, delete the secret and open the dialog again: the finding is Secret missing, the dialog says Restore blocked and "Blocked by the preflight", and the button reads Restore with bypass on dev, enabled only for a person with restore:bypass who writes a Bypass reason. The same happens when the registry no longer has an image digest the snapshot uses (image.unresolvable). The bypass covers that one restore and is recorded. The preflight lists every finding.
A restore skips the guardrails
A restore does not ask guardrails: a freeze or the production branch rule does not stand in its way, because it is the way back from a bad deploy. Who may restore is controlled by deployment:rollback, and who may restore past a blocking finding by restore:bypass.
Clean up
If you made the secret only for this tutorial, remove the reference and the secret:
api -X PUT "$WARDN_API_URL/api/v1/deployments/$DEPLOYMENT_ID/secret-refs" -d '{"refs": []}'
kubectl --context kind-dev -n shop delete secret shop-dbNext
From a push to production
Environments, previews, the production branch rule and a rollback across three clusters.
Run a database migration before an apply
Jobs with an undo job, so a restore can go back across a schema change.
Ignore fields an autoscaler owns
Keep the replica count out of drift.
Related: Held snapshots, Drift, Restore and rollback, Snapshots.
From a push to production
Set up dev, staging and production environments, get a preview for every pull request, let production take snapshots only from a protected branch, and roll back a release that was wrong.
Protect production
Put guardrails on a production environment, hold its deploys every Friday afternoon with a recurring freeze, excuse one deployment with an exception that has a review date, and see what a blocked deploy looks like.