How-to guide / Operate a cluster
Preview changes with kix plan
These docs describe Kix's main branch, which can include changes not yet released. Read the docs for the latest release.
kix plan previews a deploy in two ways, and neither changes the cluster:
kix planruns the deploy with every write sent as a server-side dry run. Use it to preview a deploy you are about to run. It needs the same permissions as the deploy.kix plan --read-onlyonly reads. Use it where the job has read-only credentials, such as a pull request check.
For a pull request check with no cluster access at all, compare against a
snapshot with kix diff; see
Use snapshots for offline or CI diffs.
Preview a deploy with kix plan
Section titled “Preview a deploy with kix plan”Run the plan with the flags you will deploy with:
❱ kix plan how-to-application --prune The output is the package-grouped plan kix deploy prints before it asks for
confirmation. Each field change is what the apiserver says the apply would
produce. After the packages, the plan lists anything the deploy would stop
on: a field another manager owns, a webhook or admission policy denial, a
validation error, an immutable field, or an RBAC refusal. Every refusal is
listed, so you can fix them all before deploying.
The plan exits 0 when the deploy would change and delete nothing, 2 when
it would change or delete something, and 3 when it would stop. In CI, treat
0 and 2 as success and block on 3, a deploy the cluster would refuse;
kix plan has a script that does
this.
Objects whose CRD or namespace the same deploy creates cannot be checked by a dry run. The plan lists them under “Not checked by the dry run” with the changes from comparing builds. On a cluster’s first deploy most objects are in this list.
Compare desired and live resources with kix plan --read-only
Section titled “Compare desired and live resources with kix plan --read-only”Start from a cluster that matches what is deployed. Kix compares only the fields it applied, so an unchanged cluster reports nothing and exits 0:
❱ kix plan how-to-application --read-only
Connecting to context kind-kix-docs (https://127.0.0.1:40563)...
⠁ Fetching live cluster state... Discovering API resources...
Fetching managed resources (62 resource types)...
Fetched 15 resources across 62 resource types
4 packages: 4 unchanged, 0 changed, 0 added, 0 removed
No differences found. Now change the production message in the cluster definition and run the same command:
❱ kix plan how-to-application --read-only
Connecting to context kind-kix-docs (https://127.0.0.1:40563)...
⠁ Fetching live cluster state... Discovering API resources...
Fetching managed resources (62 resource types)...
Fetched 15 resources across 62 resource types
4 packages: 3 unchanged, 1 changed, 0 added, 0 removed
how-to-app
~ production 1.0.0 (1 changed, 4 tracking annotation only)
~ ConfigMap/production@how-to-app
~ $.data.index.html:
--- old
+++ new
@@ -1 +1 @@
-Hello from production
+Updated production message
~ Deployment.apps/production@how-to-app (tracking annotation only; no spec change or restart)
~ Job.batch/production-health@how-to-app (tracking annotation only; no spec change or restart)
~ PackageInstance.kix.run/production@how-to-app (tracking annotation only; no spec change or restart)
~ Service/production@how-to-app (tracking annotation only; no spec change or restart)
Activation: how-to-application-6n94gibgl7zv -> how-to-application-2hrvz7i1aj05
Made by a read-only comparison with the cluster. Not checked: admission webhooks, admission policies, field ownership conflicts, and invalid objects; `kix plan` checks them.
(exit code: 2) The report names the ConfigMap you edited and shows the changed value. The resources marked “tracking annotation only” have no content change of their own. Their identity hash moves because they depend on the ConfigMap, so Kix writes them again on the next deploy to update the annotation. Their pods do not restart.
Read the report
Section titled “Read the report”The report is grouped by package, and each line tells you something different:
- A package marked added or removed appears on only one side.
- A resource marked
~has a content change, shown as a diff of the fields that differ. - A resource marked “tracking annotation only” has no content change of its own. Only its identity hash moved, because something it depends on changed.
- A cluster-level group collects resources that belong to no package, such as namespaces and custom resource definitions.
- A deployment record line names the deployment record this change would create.
Read the packages you edited first, then the dependent resources, which tell you how far the rollout reaches. A non-empty report exits with status 2, which lets CI tell a change from a clean comparison.
When the deployed build is on this machine, a field someone changed on the
cluster is tagged (reverts drift) when the deploy puts it back, and a
Drift section at the end names the field manager that changed it. When there
are changes, the last line reminds you that a read-only plan cannot see
admission webhooks, field ownership conflicts, or deploy refusals. Run
kix plan without --read-only for those.
Select the flake and context
Section titled “Select the flake and context”By default, Kix evaluates the current directory and reads the current kubectl context. Set either input explicitly when needed:
❱ kix plan how-to-application --read-only --flake ./infrastructure --context kind-kix-demo The flake supplies the desired manifests. The Kubernetes context supplies the live manifests being compared.
Produce review-friendly output
Section titled “Produce review-friendly output”Select Markdown output when attaching the result to a pull request or change review:
❱ kix plan how-to-application --read-only --output markdown Show outputHide output · 31 lines
Connecting to context kind-kix-docs (https://127.0.0.1:40563)...
⠁ Fetching live cluster state... Discovering API resources...
Fetching managed resources (62 resource types)...
Fetched 15 resources across 62 resource types
### kix plan --read-only
**Plan:** 1 updated, 0 added, 0 removed, 3 unchanged
**Resources:** 1 changed in content, 4 tracking annotation only (no spec change or restart)
#### Changed packages
<details>
<summary><code>how-to-app/production</code> 1.0.0 (1 changed, 4 tracking annotation only)</summary>
**Modified resources:**
- `ConfigMap/production@how-to-app` (1 diffs)
**Tracking annotation only (dependency changed, no spec change or restart):**
- `Deployment.apps/production@how-to-app`
- `Job.batch/production-health@how-to-app`
- `PackageInstance.kix.run/production@how-to-app`
- `Service/production@how-to-app`
</details>
**Deployment record:** `how-to-application-6n94gibgl7zv` → `how-to-application-2hrvz7i1aj05`
> Made by a read-only comparison with the cluster. Not checked: admission webhooks, admission policies, field ownership conflicts, and invalid objects; `kix plan` checks them.
(exit code: 2) Redirect it into a file for the job to publish:
❱ kix plan how-to-application --read-only --output markdown > kix-plan.md Without --read-only, kix plan --output markdown produces the same layout
with the write-path checks added, for a job that has the deployer’s
credentials.
Use JSON when another program will process the result:
❱ kix plan how-to-application --read-only --output json > kix-plan.json The document is the one a kix plan --out plan file
holds, so one consumer can read either. The checks a read-only plan cannot make read
{ "status": "not_checked", "reason": "read_only" }. By default the JSON
names each changed resource and counts its changed fields. Add
--detail fields to list each field change, old to new:
❱ kix plan how-to-application --read-only --output json --detail fields > kix-plan.json 1{ "path": "$.spec.replicas", "change": "changed", "old": 2, "new": 3, "labels": ["intended"] }change is added, removed, or changed. labels is present when the
deployed build is on this machine. Add --detail manifests to also include,
under manifests on each package, the old and new manifest of every resource
that changes, is added, or is removed, for a tool that shows a line-by-line
diff. A plan file holds those manifests too, one file each; in a kix plan
plan file the two manifests of an object the cluster checked are the live
object and the cluster’s dry-run result:
❱ kix plan how-to-application --read-only --output json --detail manifests > kix-plan.json At both levels, Secret values read (secret, not shown), or
(secret, changed, not shown) on the new side when the value changes. Secret
hashes and checksum/* annotations read (hash, not shown) or
(hash, changed, not shown). A
field value larger than 16 KiB, or a manifest larger than 3 MiB (the apiserver’s limit on a request), reads
(N bytes, not shown). A password written as a literal container env
value or into a ConfigMap is shown as it is, so keep secrets in Secrets.
Confirm a clean result
Section titled “Confirm a clean result”After deploying the intended change, run kix plan again, with or without
--read-only. A clean result confirms that Kix does not currently plan
another content change.
kix plan --read-only compares the fields Kix applied. Use
kix status <cluster> --check drift
when you need to know who else owns a field and what they changed.