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.
A guardrail is a rule your organization sets about what may reach a place. This tutorial puts three kinds of control on one production environment and then tries each: a rule about which branch production takes, a freeze that repeats every week, and an exception that lets one deployment carry on regardless.
It takes about 40 minutes and ends with:
- a production environment covered by the built-in branch rule, a stricter rule of your own, and the built-in freeze rule;
- a recurring freeze for Friday afternoons;
- an exception for a sandbox deployment, with a review date;
- two blocked deploys that you caused and read.
What this does not cover
Moving a snapshot along a pipeline stage by stage, with stage rules, is in A QA stage with sign-off; there are no promotion steps here. Guardrails judge snapshots that arrive from git in the same way as a promotion you make by hand or a pipeline makes for you.
You need:
- A connected cluster, called
prodhere (Connect a cluster), and the appwebfrom Deploy your first app, whose manifests are indeploy/webonmain. - A GitHub repository with the Wardn GitHub App installed, and
mainprotected in the branch settings. The branch rule trusts what the git host reports; for a host that cannot report protection, name the branch instead, as in Production protected-branch rule. - The Owner role. Creating guardrails and freezes needs
guardrail:manage, and exceptions needexception:manage; the Owner holds both, and an Admin holds neither by default. WARDN_API_URL,WARDN_TOKENand this helper:
api() { curl -fsS -H "Authorization: Bearer $WARDN_TOKEN" -H 'Content-Type: application/json' "$@"; }Approvals are built
A guardrail that requires approvals holds a snapshot until enough people approve it, and opens an approval request for them. This tutorial does not ask for approvals, to keep production moving while you learn; Two approvals for production adds them.
What you will set up
| Part | Setting |
|---|---|
| Environment | production, class production, holding the cluster prod |
| Deployments | web-production (namespace shop) and web-sandbox (namespace shop-sandbox), both following main |
| Rules | Built in: Protected branch for production and Org freezes. Yours: Production takes main only |
| Freeze | Fridays 14:00 to 23:59, Europe/Berlin, on everything of class production |
| Exception | web-sandbox is excused from Org freezes, with a review date |
Make the places
Create the environment as in the environments guide: Environments › New environment, Name production, Class production. Assign the cluster prod to it with Assign to an environment under Clusters not in an environment. The class is what ties it to the built-in rule, so spell it exactly.
Wardn applies as wardn-deployer in each namespace, so make two:
for ns in shop shop-sandbox; do
kubectl --context kind-prod create namespace "$ns"
kubectl --context kind-prod -n "$ns" create serviceaccount wardn-deployer
kubectl --context kind-prod -n "$ns" create rolebinding wardn-deployer \
--clusterrole=admin --serviceaccount="$ns:wardn-deployer"
doneThen create two deployments of the app web, both following main and running on the Environment production (Deployment settings):
On the app's page choose New deployment twice, with Runs on Environment, Environment production, Snapshots arrive Track a branch and Branch main. The first has Name web-production and Namespace shop; the second Name web-sandbox and Namespace shop-sandbox.
Both show Healthy within a minute or two. They are in the same environment, so every rule that covers production covers both.
Read the guardrails that already apply
Open Environments › production › Guardrails. The tab lists every guardrail that reaches the environment, with Matched by (the condition that put it there), what each Covers, Exceptions here, the owner and the mode:
- Protected branch for production matches because its condition is
classisproduction. - Org freezes is listed under Also applies: org-wide, because it has no condition.
Both carry a Default tag and are in Enforce mode. You can change their mode, owner and requirements, but not rename or archive them. Open Guardrails › Rules for the whole list.
A decision has four outcomes: allowed, needs (something can still satisfy it), wait (a fact is unknown right now, so the deploy is tried again) and blocked. Rules can only add requirements, never remove one, so a new rule can only make production safer. How a decision is made has the detail.
Add a stricter rule, in Warn only first
The built-in rule accepts any branch the git host reports as protected. Suppose you protect release/* branches too, but production should only ever take main. Add a rule for that.
Start in Warn only: it records what it would have held and holds nothing, so you can see its reach before it bites.
Open Guardrails › Rules and choose New guardrail. Name it Production takes main only. Under Applies to add a row with Field class, Operator is and Value production; the chips under the table show how many deployments, apps and clusters it reaches (two deployments here). Under Requires choose Add requirement and pick the protected-branch type. Under Mode choose Warn only, then Create guardrail.
The requirement row has no field for a branch name in the web app, so the rule as saved asks for a protected branch, not for main. Use the API tab to name main.
A warn-only guardrail records its result as noted, and the list shows "Would have blocked N this month". When you are happy, set the mode to Enforce: on the guardrail's page choose Enforce, then Save version 2. Through the API, PUT /guardrails/{id} with the same body, "mode": "enforce" and "expectedVersion": 1. History keeps every version, and each stored decision names the version it used.
Freeze Friday afternoons
A freeze holds deploys for a period. Every Friday from 14:00 until the end of the day nothing should reach production.
Open Guardrails › Freezes and choose New freeze.
- Under Details, Name
Friday freezeand a Reason written for the person it blocks: "No deploys before the weekend". - Under Covers add
classisproduction. - Under When choose Recurring, set Starts to the first Friday at 14:00, Ends to 23:59 the same day and Time zone
Europe/Berlin. The form says "Repeats every Friday from 14:00 to 23:59." - Set Releases already rolling out to Let them finish, and choose Create freeze.
The list shows it as "Recurring · Fri 14:00". A freeze is not a rule of its own: Wardn works out which freeze is active for a deployment, and the built-in Org freezes guardrail asks that none is. So a freeze holds deploys only while Org freezes is in Enforce mode. If you switch that guardrail to Warn only or Off, freezes are recorded and hold nothing. A recurring Friday freeze is this step as a recipe.
Excuse the sandbox, with a review date
The sandbox deployment is where the team tries things on the production cluster, and it should keep deploying through a freeze. Do not edit the rule; add an exception, a standing carve-out that leaves one place out of one guardrail.
Open Guardrails › Exceptions and choose Add exception.
- Guardrail: Org freezes.
- Skips: Deployment, then Name
web-sandbox. - Why: "Sandbox for load tests; must keep deploying during freezes". It is shown to everyone who reads the guardrail.
- Leave Ends empty, so the exception is permanent and gets a review in six months. Choose Add exception.
On Exceptions the new row shows Permanent under Lasts and a date under Next review. After that date it is flagged Review overdue until someone chooses Review, which sets the next date six months on. Keep this list short: a permanent exception is a decision that the rule does not hold there. Exceptions covers who may add one and how to end it.
Cause a freeze block
Waiting for Friday is slow. Make a freeze that is active now for half an hour, on the same scope:
# GNU date; on macOS use: date -u -v+30M +%Y-%m-%dT%H:%M:%SZ
NOW=$(date -u +%Y-%m-%dT%H:%M:%SZ); LATER=$(date -u -d '+30 minutes' +%Y-%m-%dT%H:%M:%SZ)
FREEZE_ID=$(api -X POST "$WARDN_API_URL/api/v1/freezes" -d '{
"name": "Test freeze",
"reason": "Trying the freeze in the Protect production tutorial",
"scope": [{"field": "class", "op": "is", "value": "production"}],
"kind": "one_time", "startsAt": "'"$NOW"'", "endsAt": "'"$LATER"'", "timeZone": "UTC"
}' | jq -r .id)Change deploy/web/configmap.yaml and merge the change to main. Within a minute, web-production renders the commit and does not apply it. Open Deployments › web-production › Snapshots: the snapshot is stored and shown as held by the guardrail, and the deployment keeps running what it ran. Audit › Activity has a guardrail.blocked entry whose message names the rule and the freeze:
Guardrail "Org freezes" holds this snapshot: No deploys during freezes (Test freeze).Meanwhile web-sandbox applied the same commit, because its exception leaves it out of Org freezes:
kubectl --context kind-prod -n shop-sandbox get cm web-config -o jsonpath='{.data.GREETING}'
kubectl --context kind-prod -n shop get cm web-config -o jsonpath='{.data.GREETING}'The first shows the new value, the second the old one. Now end the test freeze:
api -X POST "$WARDN_API_URL/api/v1/freezes/$FREEZE_ID/cancel"Nothing applies the held snapshot by itself when a freeze ends. Push another commit and web-production renders it afresh, and it applies. The web app has no cancel button for a freeze yet; the API call stops it at once and lists it as ended.
Cause a branch block
Point production at a branch that is not main. Create one and push it, then open web-production › Settings, set Branch to feature-x and choose Save:
git switch -c feature-x
git commit --allow-empty -m "Try a feature branch in production"
git push -u origin feature-xThe snapshot comes from a branch GitHub does not report as protected, so it is blocked and stored, never applied. The message names one guardrail and the requirement that failed, in the form Guardrail "<name>" holds this snapshot: <requirement>, for example Guardrail "Protected branch for production" holds this snapshot: Snapshot from the protected branch.
Open the decision from Activity to see every guardrail that judged it. Production takes main only is judged too, and holds it as well, once you have set it to Enforce. Set Branch back to main.
A person with release:bypass can let one blocked snapshot through, once, with a reason, for a hotfix that cannot wait (One-time bypass). A bypass lifts only the branch rule; a freeze still holds. That duty is not held by the Admin role.
Guardrails do not stand in the way of a restore. During a freeze, the way back from a bad deploy stays open to whoever holds deployment:rollback.
Keeping it honest
- Read Guardrails › Rules and Exceptions when their tiles show Review overdue or Expiring.
- Freezes and windows set to "the organization's time zone" use UTC until you change it with
PUT /policy-settings(Organization time zone). - Try each new rule in Warn only before you enforce it, and look at "Would have blocked" first.
Clean up
Delete the two deployments from their Settings tabs, end or delete the exception (End now), cancel the Friday freeze if it was only for the tutorial, archive Production takes main only with POST /guardrails/{id}/archive, and remove the namespaces:
kubectl --context kind-prod delete namespace shop shop-sandboxNext
A recurring Friday freeze
The freeze on its own, as a copyable setup.
Guardrails
Every requirement, scope field and mode.
Read-only access for an on-call team
Control who may see production, as well as what may reach it.
Related: Guardrails concept, Exceptions, Freezes, Pipelines and promotion.
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.
From incident to fix PR with an RCA agent
Connect a Claude Code agent, let it triage an incident in a sandbox, read what it found, and follow its proposed code fix from approval to a pull request that only you can merge.