# `deploy`

`kix deploy` builds a cluster, compares the build with the activation the
cluster runs now, checks the plan with a server-side dry run, shows it, asks
for confirmation, and applies the changed resources with server-side apply. Each resource starts as
soon as the resources it depends on are ready.

This page is hand-maintained. Check `cli/kix-cli/src/cli.rs` and
`cli/kix-cli/src/commands/deploy/mod.rs` when in doubt.

## Synopsis

```text
kix deploy <CLUSTER> [-y] [--dry-run] [--plan <FILE>] [--prune | --skip-orphan-check]
           [--timeout <DURATION>] [--on-error stop|continue]
           [--reconcile] [--force-conflicts] [--accept-migrations]
           [--only <NAMESPACE/INSTANCE>]... [--offline] [--operator | --operator-removed]
           [--log-format pretty|line|json|tui] [--group-by package|namespace]
           [--flake <FLAKE>] [--context <CONTEXT>]
```

| Argument or flag | Meaning |
| --- | --- |
| `<CLUSTER>` | Cluster name to build from the flake. |
| `-y`, `--yes` | Skip the confirmation prompt. Required when stdin is not a terminal, unless `--dry-run` is set. |
| `--dry-run` | Run [`kix plan`](/docs/reference/cli/plan/) with the same planning flags and stop. Nothing changes. The exit status and `-o` handling are `kix plan`'s, and `--yes`, `--timeout`, `--on-error`, `--log-format`, and `--group-by` have no effect. |
| `--plan <FILE>` | Deploy only if the plan made now still matches a reviewed one. See [Deploy a reviewed plan](#deploy-a-reviewed-plan). With `--dry-run`, check the plan and exit without deploying. Not with `--offline` or `--operator`. |
| `--prune` | Delete orphans: resources the previous activation had and this build does not, including orphans earlier deploys kept. Without it, orphans are listed and kept, and the new Activation records where they came from so a later `kix deploy --prune` or `kix gc` deletes them. |
| `--skip-orphan-check` | Do not look for orphans at all in this run, and prune nothing. The orphans stay on the cluster for `kix gc` to find. Not with `--prune`. |
| `--timeout <DURATION>` | How long to wait without progress for each resource to become ready or for each deleted object to be removed (capped at `5m` total per object). Accepts `5m`, `300s`, or a bare number of seconds. Default `180s`. Not with `--operator`. |
| `--on-error <MODE>` | `stop` (default) stops before applying anything when the plan shows a refused write, and halts the run at the first failure and cancels what has not started. `continue` applies the plan even when it shows refused writes, cancels only the dependents of a failed resource, and carries on with the rest. Either way, a run in which any resource failed exits `1`. |
| `--reconcile` | Re-apply every resource, including those whose identity hash matches the running activation. Use it to put back fields that were changed on the cluster. |
| `--force-conflicts` | Take ownership of fields another field manager owns. Fields listed in `ownership.cede` that another manager holds are left to that manager. Without the flag, a conflict is a refused write in the plan, naming the fields and their current owner, and under `--on-error stop` the deploy stops before applying anything. |
| `--accept-migrations` | Proceed when the plan removes an object that holds data from a stateful package and adds another that holds data in its place. Without it such a deploy stops, even with `--yes`. Kix does not copy data. |
| `--only <NAMESPACE/INSTANCE>` | Deploy only this package instance and the instances and resources it depends on, leaving the rest of the build for a later `kix deploy`. Repeatable. Cannot be combined with `--prune` or `--operator`. See [Deploy one instance at a time](#deploy-one-instance-at-a-time). |
| `--offline` | Plan from the previous activation in the local cache instead of reading the cluster. Because the offline plan compares the new build only against the build this machine last deployed, it cannot see live cluster drift, interrupted deploys, or kept orphans from earlier deploys. With `--dry-run`, nothing contacts the cluster. Without `--dry-run`, Kix stops before applying if the cached build does not match the cluster's `Active` build in the current context (the cache is keyed by cluster name alone, so another context's cluster with the same name may have written it). After you confirm the offline preview, Kix connects, plans again against the live cluster, and proceeds only if the live plan writes and deletes the exact same objects. Otherwise it stops with `[K3811]` before taking the deploy lock, lists the differing objects, and applies nothing. It also stops with `[K3811]` when an object it would write was changed on the cluster, because an offline deploy never overwrites such a change. Run `kix deploy` without `--offline` to review and confirm the full live plan. |
| `--operator` | Hand the build to the Kix operator instead of applying it from this machine. Cannot be combined with `--only`, because the operator always deploys the full build. Fails with `[K7218]` if combined with `--timeout`, `--on-error continue`, `--reconcile`, `--skip-orphan-check`, `--force-conflicts`, `--log-format` (other than `pretty`), or `--group-by` (other than `package`), because operator mode uses fixed deploy settings and progress output. See [Operator mode](/docs/reference/cli/operator-mode/). |
| `--operator-removed` | Confirm that no Kix operator is running for this Kix cluster. Before planning, Kix reclaims the cluster from an uninstalled earlier operator and clears the `[K9557]` refusal permanently. Cannot be combined with `--operator`. See [Take a cluster back from a removed operator](#take-a-cluster-back-from-a-removed-operator). |
| `--log-format <FORMAT>` | `pretty` (default): interactive progress, coloured when stdout is a terminal; falls back to `line` when stdin is not a terminal. `line`: one plain line per resource outcome. `json`: JSON deploy events, one per line, ending with a `summary` object; stdout holds only the events, and the plan and other text go to stderr. `tui`: a live dependency tree while deploying; falls back to `line` when the terminal is not interactive. |
| `--group-by <GROUP>` | How `--log-format tui` groups the tree: `package` (default) or `namespace`. Execution order does not change. Other log formats ignore it. |
| `--flake`, `--context`, `--override-input` | See [Global flags](/docs/reference/cli/global-flags/). Without `--dry-run`, `-o` accepts only `text`, and `--no-cache` has no effect; use `--log-format` to choose the deploy's output. |

Set `KIX_TUI_HEIGHT` to a number of rows to cap the live view of
`--log-format tui`. The default is half the terminal height, between 10 and 40.

## What a deploy does

1. Builds the cluster.
2. Prints the kubeconfig context and API server URL before connecting, such as
   `Connecting to context prod (https://prod.example:6443)...` (with
   `--offline`, Kix connects only after confirmation). On a first deploy when
   `cluster.kubernetes.uid` is unset, Kix also prints a note with the setting
   to [bind the definition](/docs/how-to/operate-a-cluster/bind-a-cluster-definition-to-its-kubernetes-cluster/)
   to this Kubernetes cluster. Kix reads the cluster's deployment records and
   their [`PackageInstanceRevision`](/docs/reference/annotations-crds-and-receipts/#packageinstancerevision)
   objects (which list what each deploy applied), then lists the live objects
   of every kind referenced by the build or those revisions to decide what to
   write (see
   [How a deploy decides what to write](#how-a-deploy-decides-what-to-write)).
   With `--offline`, Kix skips reading the cluster during planning and compares
   the new build against the last build deployed from this machine's local
   cache.
3. Resources from an earlier deploy that stopped part way or ran with `--only`
   are folded into the plan: they are re-applied or reported as orphans. Kix
   counts a resource from an unfinished deploy as present on the cluster only
   when the live object carries the `kix.run/identity-hash` recorded in that
   deployment record's revision, so resources that deploy never created are neither
   reported as orphans nor deleted. Fields written by an unfinished deploy
   appear under `earlier_deploys` attributed to that deployment record instead
   of appearing as drift.
4. Sends every write and prune delete of the plan as a server-side dry run,
   the way [`kix plan`](/docs/reference/cli/plan/) does, and prints the
   result: the changed resources (with field changes under `-v`), the
   writes the cluster would refuse, prune fates, drift, and the objects the
   dry run could not check. The dry run is skipped when there is nothing to
   apply or prune. It also prints
   warnings for node labels that `DoNotSchedule` spread or affinity rules
   need but no schedulable node carries, and whether the working tree has
   uncommitted changes. Under `--on-error stop`, a plan with a refused write
   or a refused prune delete stops the deploy here, before anything is
   applied. With `--offline` the plan is not sent to the cluster.
5. Asks for confirmation, then takes the cluster's
   [deploy lock](#the-deploy-lock), creates the Activation record and its
   revisions, and applies. Kix writes nothing to an unchanged resource. A
   deploy with nothing to change exits without applying. After each apply,
   Kix records the hash of what it applied in the revision's
   `status.applied`. When a Secret carries `kix.run/sops-source`, the deploy
   decrypts the SOPS file and keeps any plain keys already in the Secret's
   `stringData` or `data`. Kix converts any `stringData` entries and sends all
   Secret values base64-encoded under `data`, so Kix owns each key on the
   cluster. Before the record is created, the run stops if the
   cluster serves a resource's kind as namespaced and its manifest has no
   `metadata.namespace`, naming each such resource. Cross-resource
   [check 18](/docs/reference/validation-checks/)
   refuses most of these at evaluation; this covers custom kinds whose
   CustomResourceDefinition is not in the build.

   If an object the deploy applies is already being deleted on the cluster
   (it has a `deletionTimestamp`, usually while a finalizer runs), Kix waits
   for Kubernetes to finish deleting the old object and then creates a new
   one from the build. Applying onto a deleting object would let Kubernetes
   remove it as soon as its finalizers cleared. The replacement keeps none of
   the old object's data; for example, a PersistentVolumeClaim starts with an
   empty volume. The plan warns about these objects under
   `... being deleted on the cluster`. If the old object is still on the
   cluster after `--timeout` passes without a finalizer being removed, or
   after 5 minutes in total, the deploy fails with `[K2794]` without creating
   the replacement. This also applies to resources that did not change in the
   build, as long as the account can list their kind. With `--offline`,
   planning does not read the cluster, so the deploy catches a deleting object
   only if that resource changed in the build or you pass `--reconcile`.
6. Prunes orphans when asked. Namespaces and CustomResourceDefinitions are
   reported as kept and never deleted, with or without `--prune`. In
   `--log-format json`, the `prune_start` event lists them under `kept`,
   apart from the `resources` that prune may delete.

   An orphan that another Kix cluster still deploys is not pruned. The plan
   lists it as kept (`kept <resource>, still deployed by Kix cluster <name>`),
   determined from that Kix cluster's deployment records and revisions and from
   `metadata.managedFields` on the live resource. At the start of pruning, Kix
   releases this cluster's field ownership on each shared resource with an
   empty Server-Side Apply so the other Kix cluster owns it alone. If that
   apply fails, the resource stays on the kept-orphans list so the next deploy
   retries. `kix rollback --prune` and default `kix gc` follow the same rule.
   With `--offline` the plan has not read
   the cluster yet, so it says the check comes once the deploy connects.
   The prune checks each orphan again right before deleting it, and leaves
   one that another cluster started deploying, or that changed, since the
   plan (`prune_kept` in `--log-format json`).

   Orphans kept by a deploy remain pruneable. The finalized Activation links a
   kept-orphans revision listing them alongside any orphans from earlier
   deploys that still exist on the cluster. The next deploy's plan includes
   them again so `kix deploy --prune` or default `kix gc` deletes them. Once
   all kept orphans are deleted, the Activation omits the kept-orphans
   revision. Any orphan whose resource kind the cluster does not currently
   serve stays on the list. If the kept-orphans revision is missing or
   unreadable, the deploy refuses to prune. Run `kix gc --full-scan` to
   rebuild it.

   With `--prune`, Kix deletes dependents before the objects they depend on,
   deletes independent objects in parallel, and waits for each object to be
   removed from the cluster. If an object is already being deleted, Kix waits
   for that deletion instead of sending a second delete request. Kubernetes
   keeps a deleted object until every entry in `metadata.finalizers` is
   removed, usually by the controller or operator that added it after finishing
   its cleanup. Kix stops waiting if `--timeout` passes without a finalizer
   being removed, or after 5 minutes in total. Orphans whose recorded
   dependencies form a cycle are kept and reported (`prune_kept` in
   `--log-format json`), because Kix cannot choose a safe deletion order.

   If an object is still on the cluster when the wait ends, the deploy fails
   with `[K2794]` (exit code `1`), marks the Activation `Degraded`, and lists
   any remaining finalizers and how long Kix waited. Kix skips deleting any
   orphans that the build records as dependencies of the stuck object, reports
   them as kept (`prune_kept` in `--log-format json`), and keeps those orphans
   on the kept-orphans list so the next `kix deploy --prune` or `kix gc` tries
   again. When a package sets `controller` on `scope.mkCRD`
   or `scope.mkCRDRef`, custom resources of that kind depend on the operator,
   and `[K2794]` also names the operator and reports whether it is ready, not
   ready, or not on the cluster. `[K2794]` reports the same operator status if
   Kix times out waiting to delete an object before recreating it in place, or
   waiting for an object in the build that was already being deleted on the
   cluster. In `--log-format json`, any resource that fails with `[K2794]`
   carries `deletion_unfinished` under `detail`, with `elapsed_ms`,
   `finalizers`, `message`, and `controllers` (each with `resource`, `state` of
   `ready`, `not_ready`, `missing`, or `unread`, and an optional `detail`
   reason). While `--prune` waits for a deleted object to be removed,
   `--log-format line` periodically prints a `waiting>` line, as it does for
   slow readiness checks, and `--log-format json` emits `waiting` events with
   `phase` set to `deletion`.

   Most packages do not set `controller` yet, so
   removing a custom resource and its operator in the same deploy can delete
   the operator before it removes the custom resource's finalizer. If cleanup is
   still running normally, such as pods with a long termination grace period or
   a cloud load balancer teardown, deploy again later or pass a longer
   `--timeout` (up to `5m` per delete). Kix never removes finalizers itself;
   when finalizers remain, the `[K2794]` error prints a `kubectl patch` command
   to remove them. Running that command makes Kubernetes delete the object
   immediately and leaves behind anything the finalizer would have cleaned up,
   such as an external database or cloud resource.

   To avoid relying on this list, pass `--prune` to every deploy and
   rollback. A run that deletes every orphan adds nothing to the list, so it
   stays empty; a failed delete still adds the orphan. No
   configuration setting makes `--prune` the default, so put the flag in the
   command your scripts or CI run. In
   [operator mode](/docs/reference/cli/operator-mode/) the operator deletes
   orphans on every deploy.
7. Marks the Activation `Active`, or `Degraded` or `Failed` when resources
   failed.

   Before pruning and finalizing, Kix writes the applied hashes into the
   deployment's revisions. If that write fails, the deploy stops with "every
   object reached a result, but Kix could not record the applied hashes":
   the workload objects remain applied, the new record is marked `Failed`,
   nothing is pruned, and the previous deployment record stays active. Run
   `kix deploy` again to pick up the applied objects and finish recording the
   deploy.

`Ctrl-C` cancels the run and marks the record `Failed`. A run that makes no
progress for 600 seconds is cancelled; set `KIX_STALL_TIMEOUT` to a number of
seconds to change that, or `0` to disable it. A resource that is still being
checked for readiness counts as progress. For such a wait, the plain output
prints a `waiting:` line after 10 seconds, then at 30, 60, and 120 seconds,
then every minute, naming the resource, its last readiness message, and the
readiness timeout it runs against. Retries and request timeouts
are covered in [API server retries and request limits](/docs/reference/cli/api-server-transport/).

Set `KIX_NO_INTERACTIVE` to any value to treat the terminal as
non-interactive.

## How a deploy decides what to write

`kix plan`, `kix deploy`, `kix rollback`, and the Kix operator evaluate each
object in the build against the live cluster and the cluster's revisions, in
this order:

1. **The object is missing, being deleted, or has a different `kix.run/identity-hash`.**
   Kix applies it. If the live object matches an earlier `Failed` or `Partial`
   deploy, the plan notes that deployment record.
2. **Kix has no recorded applied hash for the object.** Kix reapplies it and
   records the hash. The plan counts these objects on a `↻` line.
3. **A field Kix applied changed on the cluster.** The plan counts these
   objects on a `↺` line and lists each modified field and its current field
   manager under `Drift:`. `kix deploy` reapplies the object with force to take
   those fields back.

   Before forcing an apply, Kix sends an unforced dry-run apply to see which
   conflicting fields and field managers Kubernetes reports. Kix runs this check
   during planning and again on a fresh read right before writing, and forces
   the apply only when the conflicting fields, owning managers, and live values
   match the plan (adding three API requests during planning and one at write
   time per reverted object). Updates to `status` or to fields other than the
   conflicting ones do not block the apply. If those fields changed after planning, or if Kix cannot read the
   object before writing, the deploy stops and names the object. If the dry run
   cannot determine the conflicts during planning, Kix applies the object
   without force so the plan reports the conflict as a refused write. For some
   objects, Kix can never determine the conflicting fields from a dry run (for
   example, when the other field manager recorded its fields under another API
   version or when the kind is served by an API server that refuses dry runs),
   so the conflict appears on every deploy. Run `kix deploy --force-conflicts` to take the
   fields back (this forces every object in the deploy), or list the fields in
   `ownership.cede` if the other manager should keep them. If another
   writer modifies the object between the check and the apply, Kix retries up to
   5 times before stopping with "another writer modified it on each of the 5
   times Kix read it". Stop whatever is continuously updating the object and run
   `kix deploy` again.

   Fields listed in
   [`ownership.cede`](/docs/how-to/adopt-existing-resources/cede-fields-to-a-controller/)
   never count as drift, and forced applies omit any ceded field owned by
   another manager so that manager keeps it. Kix also never forces fields away
   from another Kix cluster: it applies those objects without force (counted on
   a `↻` line), so Kubernetes adds this cluster's field manager entry when
   values match and rejects the apply with `[K5636]` when they conflict. When
   only the dry run reveals that another Kix cluster holds a field (for
   example, a Secret value set in `stringData`), the plan counts the object on
   a `↺` line, and Kix still applies it without force.

Kix leaves all other objects in the build untouched. `--force-conflicts` forces
every apply, including objects matched by rule 1. Without it, a field ownership
conflict on rule 1 stops the deploy.

During planning, Kix sends one cluster-wide `list` request for each resource
kind referenced by the build or the revisions. If your Kubernetes account
cannot list a kind cluster-wide, Kix falls back to `get` for each individual
object, and stops naming the missing permissions only when the account can
neither `list` nor `get` that kind.
The first deploy after upgrading to revisions requires cluster-wide `list`
across all resource kinds on the cluster whenever an earlier deployment record
lacks object names (as in Kix 0.9 and earlier) or keeps orphans. Kix lists every
object carrying `app.kubernetes.io/managed-by=kix` to find what that record
deployed, and stops with `[K9558]` naming any kinds it cannot list. Grant
cluster-wide `list` on those kinds or run that first deploy once with an account
that has it (see
[The first deploy after upgrading](/docs/explanation/server-side-apply-and-drift/#the-first-deploy-after-upgrading)).
In the [`Plan` document](/docs/reference/cli/plan/#the-plan-document),
`objects.writes[].reason` records why Kix writes any object whose manifest did
not change in the build.

On the first deploy of a Kix cluster after upgrading, Kix converts earlier
deployment records to revisions before modifying any workload object, and
updates each object's metadata once to remove the retired annotations. `kix plan`
reports that count on an `Upgrade:` line. See
[The first deploy after upgrading](/docs/explanation/server-side-apply-and-drift/#the-first-deploy-after-upgrading).

## The deploy lock

Only one run can change a Kix cluster at a time. Each Kix cluster has an
`ActivationHead` object, named after the cluster, that holds its deploy lock
(see [`ActivationHead`](/docs/reference/annotations-crds-and-receipts/#activationhead)).
`kix deploy`, `kix deploy --only`, `kix rollback`, `kix gc`, `kix migrate
domain`, and the Kix operator take the lock before changing the cluster.
Commands run with `--operator` do not take the lock themselves; they submit a
request to the Kix operator, which takes the lock. Before taking the lock, Kix
installs any missing Kix CustomResourceDefinitions, which requires `get` and
`create` permissions on `customresourcedefinitions` once (see
[Kix's own CRDs](/docs/reference/annotations-crds-and-receipts/#activationhead)).
Every command that modifies a Kix cluster stops with `[K9557]` before planning
if a current, queued, or deploying record for that cluster was submitted to the
Kix operator and the operator does not advertise the `revisions` feature
(including operators from Kix 0.9 or earlier), because an older operator would
write back the retired annotations. Other Kix clusters on the same Kubernetes
cluster are unaffected. Kix cannot tell whether an older operator is still running or
was uninstalled. If the operator is still running, upgrade it first
(see [Operator mode](/docs/reference/cli/operator-mode/#requirements)). If it
was uninstalled, run `kix deploy <cluster> --operator-removed` once (see
[Take a cluster back from a removed operator](#take-a-cluster-back-from-a-removed-operator)).

Right after building and connecting, before reading cluster state for the
plan, `kix deploy` checks whether another run holds the lock. If the lock is
held, Kix prints the holder and watches the lock:

- If the holder renews its lock (which an active run does every 10 seconds),
  `kix deploy` exits with code `1`, prints who holds the lock and what it is
  doing, and changes nothing.
- If nothing renews the lock for 30 seconds, Kix assumes that run stopped,
  takes over the lock, and marks any other record the stopped run was
  deploying as `Failed`.
- If the Kix operator holds the lock for drift repair, `kix deploy` asks it to
  yield and waits up to 60 seconds for it to release the lock.

After taking over an expired lock, `kix deploy` releases the lock before
reading the cluster so the plan reflects the cleaned-up state. Once you
confirm the plan, `kix deploy` takes the lock again to apply changes (watching
again if another run acquired it in the meantime). `kix rollback`, `kix gc`,
and `kix migrate domain` check and take the lock the same way. Read-only
commands (`kix plan`, `kix status`, and `--dry-run`) never wait for or take
the lock.

```text
Kix cluster prod is locked by another run: kix deploy by ana@laptop, process 4242 (deploy of record prod-3f2a9c1b04de).
  Nothing was changed on the cluster.

  Why:
    Only one run can change a Kix cluster at a time. That run renewed its lock while Kix was watching, so it is still active.

  Next:
    Wait for that run to finish, then run this command again. If that run stops unexpectedly, its lock expires 30 seconds after its last renewal and the next run will take it over.
```

The lock also tracks a generation number (`status.generation`), which
increments whenever a run that modified the cluster finishes or when Kix takes
over an expired lock. Each plan records the generation it read. After you
confirm and `kix deploy` takes the lock, it exits with code `1` if the
generation changed, because another run modified the cluster after the plan
was built:

```text
Kix cluster prod changed after this plan was made (deploy lock generation 7, now 8).
```

Run the command again to build a fresh plan. An offline plan does not read the
cluster's lock generation. `kix deploy --offline` plans again from the live
cluster once it connects, and binds the run to the generation that plan read.

If a running command cannot renew its lock, it stops writing to the cluster 20
seconds after its last renewal, 10 seconds before another run can take over
the lock. Kix measures elapsed time against both the monotonic clock and the
system clock and uses the longer duration, so a machine that slept mid-deploy
stops writing as soon as it wakes instead of overlapping with another run. The
next deploy applies any remaining resources.

`ActivationHead` also records the cluster's active deployment record and the
Kix version that last changed the cluster. A deploy updates the active record
on `ActivationHead` in a single write after applying all resources, then
updates the phases on the `Activation` records. If the deploy stops between
those two steps, the next run updates the `Activation` phases from
`ActivationHead`. If a record is left in phase `Deploying` while no run's lock
names that record in `status.lock.activation` (for example, by an older Kix
that does not use the lock), planning prints a warning with the
`kubectl patch` command to mark it `Failed`. [`kix status`](/docs/reference/cli/status/) and
[`kix plan`](/docs/reference/cli/plan/) report any current lock holder without
waiting.

### Take a cluster back from a removed operator

`kix deploy <cluster> --operator-removed` confirms that no Kix operator is
running for the Kix cluster. If a current, queued, or deploying record for the
cluster was submitted to an operator without `revisions` support, the deploy
reclaims the cluster under the deploy lock before planning:

- Any `Queued` record the operator never started is marked `Superseded`.
- Any `Deploying` record is marked `Failed` (noting `--operator-removed`), and
  the plan folds in any resources it already applied.
- `spec.source` is cleared on those records and on the active record so Kix
  treats them as deployments applied without the operator.

Because this runs before Kix shows the plan, the records remain updated even if
you decline the confirmation prompt. The deploy then continues as a normal
`kix deploy`, and subsequent commands do not need the flag. Kix cannot tell
whether an operator is still running, so after it takes the cluster back it
prints a `kubectl` command that looks for pods whose name or image contains
`kix-operator`. Kix does not install the operator, so its pods may have
another name. If no matching operator-submitted record exists, the flag
changes nothing and Kix prints a line that says so. Rolling back with
`kix rollback` to an older operator-deployed record restores that record (with
its `spec.source`) as active, which triggers `[K9557]` again until you pass
`--operator-removed` once more.

Never pass `--operator-removed` while an older operator is still running, or it
will continue writing back the retired annotations. `--operator-removed` cannot
be combined with `--operator`. `kix plan --operator-removed` previews the
deploy without modifying the cluster, and refuses `--out` because
`kix deploy --plan` reclaims the cluster before checking the saved plan (which
advances the deploy lock generation and makes the saved plan out of date). Run
`kix deploy <cluster> --operator-removed` without `--plan` instead.

## Required stops

A few releases change what Kix stores in the cluster, and every cluster must
be deployed with them once before it moves to a newer minor. `kix deploy`
reads the Kix version that last changed the cluster from the
[deploy lock](#the-deploy-lock) (`ActivationHead`), or from the active
record's deploy receipt if no lock-aware version of Kix has written to the
cluster yet. It
refuses before it applies anything when that version is older than such a
release and the Kix deploying now is newer than the release's minor:

```text
Deploy blocked: cluster dev was last deployed with Kix 0.10.0, and cannot skip required stop Kix 0.11.0 on the way to Kix 0.12.1.
Nothing was applied to cluster dev.

Every cluster deployed with Kix older than 0.11.0 must be deployed once with Kix 0.11.x before deploying Kix 0.12.1.

Next: check out the commit where this project was pinned to Kix 0.11.x (for example with `git worktree add` or `git checkout`), run `kix deploy dev` from there, then return here and run `kix deploy dev` again.
```

A deploy with a Kix of the release's own minor passes, and so does a cluster
with no receipt, such as one never deployed. `kix deploy --dry-run` and
`kix plan` do not check.

`kix rollback` and `kix gc` run the same check because both write to the
cluster. `kix rollback` stops with `Rollback blocked:` and tells you to roll
back from a commit pinned to the required stop's minor version; `kix gc` stops
with `Garbage collection blocked:` and tells you to deploy with that minor
version first. The in-cluster operator checks
its own Kix version the same way. It marks the queued Activation `Failed` with
the reason and emits a `RequiredStopSkipped` event, so `kix deploy --operator`
and `kix rollback --operator` stop there too. [`kix upgrade`](/docs/reference/cli/upgrade/)
stops at such a release, so a project normally deploys it on the way.

## Deploys by an older Kix

`kix deploy` stops before applying anything if a newer minor version of Kix
last changed the cluster. Kix reads that version from the cluster's
[deploy lock](#the-deploy-lock) (`ActivationHead`), which records the Kix
version that last finished a deploy, rollback, or garbage collection (whether
from the CLI or the operator). If `ActivationHead` has no writer yet, Kix
falls back to the active record's
[deploy receipt](/docs/reference/annotations-crds-and-receipts/#deploy-receipt-schema),
which also supplies the deployed commit when it matches that version:

```text
Deploy blocked: cluster prod was last deployed with Kix 0.9.1 (from commit abc1234), and this is Kix 0.8.4.
Nothing was applied to cluster prod.

Kix 0.8.4 may not understand what Kix 0.9.1 wrote to the cluster. Once Kix 0.9 has changed a cluster, only Kix 0.9 or newer can deploy, roll back, or garbage-collect it.

Next: switch to a commit that uses Kix 0.9 or newer, or upgrade this project to Kix 0.9 or newer with `kix upgrade`. Then run `kix deploy prod` again.
To deploy with Kix 0.8.4 anyway (for example, to downgrade from a broken release), set KIX_ALLOW_DOWNGRADE=0.9.1. Cluster prod's deployment record will note the downgrade from Kix 0.9.1.
```

An older patch release of the same minor version is allowed, and so is a
cluster whose receipt names no Kix version.

To downgrade a cluster on purpose (for example, from a broken release), set
`KIX_ALLOW_DOWNGRADE` to the exact Kix version that last deployed the cluster
(such as `0.9.1`). Kix then allows the deploy or rollback and writes that
version to the `kix.run/downgraded-from` annotation on the `Activation` record.

Other commands and flags handle this check as follows:

- **`kix rollback`**: Checks the running Kix version against the cluster's last
  deploy, regardless of which Kix version built the rollback target. Honors
  `KIX_ALLOW_DOWNGRADE`.
- **`kix gc`**: Stops with `Garbage collection blocked:`. `KIX_ALLOW_DOWNGRADE`
  does not apply to `kix gc`, because an older Kix could delete resources
  tracked in fields only the newer version understands.
- **Operator mode (`--operator`)**: The Kix operator checks its own Kix
  version, marks the queued `Activation` `Failed`, and emits an `OlderKix`
  event. The operator has no downgrade override; run `kix deploy` or
  `kix rollback` without `--operator` to downgrade a cluster.
- **`kix plan`, `kix plan --read-only`, `kix deploy --dry-run`, and `kix rollback --dry-run`**:
  Print a warning and still show the plan.
- **`kix deploy --offline`**: Runs the check after connecting to apply, before
  changing the cluster. `KIX_ALLOW_DOWNGRADE` does not work with `--offline`;
  run `kix deploy` without `--offline` to downgrade.

## Deploy a reviewed plan

Save the plan a reviewer approves as a
[plan file](/docs/reference/cli/plan/#plan-file), then deploy with it:

```bash
kix plan prod --out plan.kixplan   # reviewed and approved
kix deploy prod --plan plan.kixplan --yes
```

The deploy reads only plan files. It refuses a file that is not one, and a
plan file whose manifests do not match their names, before it builds
anything.

The deploy builds and plans again with the planning flags recorded in the
plan, and applies nothing if the new plan differs from the reviewed one on
any of these:

| Compared | What differs |
| --- | --- |
| Cluster | The plan is for another Kix cluster. |
| New build | The build's identity hash. A store path that moved, with the same manifests, still matches. |
| Deployed build | The identity hash of the build the cluster runs: another deploy landed after the review. |
| Lock generation | The generation of the cluster's [deploy lock](#the-deploy-lock): another run modified the cluster after the plan was saved (such as `kix deploy --only` or `kix gc`). Skipped when the saved plan has no lock generation (for example, from `--offline` or an older Kix). |
| Planning flags | `--prune`, `--skip-orphan-check`, `--reconcile`, `--force-conflicts`, `--accept-migrations`, `--operator-removed`, or `--only`. Passing a flag on the command line that was not set when the plan was saved fails before building. `--only` must match the saved plan: pass the exact same `--only` instances for a partial plan, and omit `--only` for a full plan. |
| Refusals | A conflict, by object, or an admission refusal, by object and reason, that the reviewed plan did not have. |
| Reverted drift | A drifted field (by object and path) that the deploy would restore and the reviewed plan did not list, or one whose field managers or live value changed since the plan was saved. Plans saved by earlier versions omit live values, so Kix compares only field paths for them. Plan files omit Secret values and replace values over 16 KiB with their byte length, so checking a saved plan cannot detect a second change to a Secret value or a same-length change over 16 KiB (though the deploy still verifies exact live values between its fresh plan and the write). |
| Prune deletes | An orphan the deploy would delete that the reviewed plan did not list. |
| Objects not checked | An object the dry run checked for the reviewed plan and cannot check now, for example because a webhook it calls lost dry-run support. Its refusals and drift would not show. |

What the reviewed plan had and the new one does not, such as a conflict
someone resolved, does not refuse the deploy. Messages, `resourceVersion`s, and order are
not compared. Field managers and live values are compared only for reverted drift.

The planning flags come from the plan: a flag it has and the command line
omits still applies. A plan whose sections do not match how it says it was
made, for example a `kix plan` document with prune marked not checked, was
edited after it was written and is refused. The deploy prints the file's
SHA-256 so an approval system can check it used the file it approved.

A refusal lists what differs and exits `4`. The comparison runs before the
check for stateful migrations, so a plan that no longer matches exits `4`
even when the new build would also stop on a migration. `kix deploy --plan plan.kixplan
--dry-run` makes the same comparison without deploying. It exits `4` when the
plan no longer matches, `3` when it matches but the deploy would stop on a
refused write or a migration not accepted, and `0` otherwise. With
`--output json` it prints `{ plan_sha256, matches, mismatches, skipped, kix_differs }`.

A plan file written by [`kix plan --read-only`](/docs/reference/cli/plan/#read-only-plans)
or [`kix diff --out`](/docs/reference/cli/diff/) is refused: a read-only
comparison plans no deploy, so it lists no objects for the deploy to be held
to. So is a plan that compared two builds without reading the cluster
(`made_by: builds`).

The checks above catch an edited plan only when its sections contradict how
it says it was made. Adding items to a list, or marking a drift section not
checked, makes the comparison weaker without making the file inconsistent,
so an approval system should check the SHA-256 the deploy prints against the
file it approved.

When the plan was made by a different build of Kix (another store path), or of
another version, the deploy prints a note and does not refuse. Two binaries
built outside the store with the same version print no note.

## Deploy one instance at a time

When an upgrade changes many package instances, pass `--only` to deploy one or
more instances and their dependencies first so you can verify each step before
deploying the rest:

```bash
kix plan prod --only data/postgres          # preview this step
kix deploy prod --only data/postgres
kix deploy prod --only web/shop --only web/api
kix deploy prod                             # deploy the rest of the build
```

Pass each instance as `<namespace>/<instance>`, matching the package names in
`kix plan`. If a name does not match any instance in the build, Kix stops
before changing the cluster and lists the build's instances. If you omit the
namespace and the name matches an instance, Kix suggests the full
`<namespace>/<instance>` name.

`--only` always deploys whole package instances so no instance is split across
builds. Kix starts with the resources in your selected instances and follows
their `kix.run/depends-on` dependencies. Whenever a dependency belongs to
another package instance, Kix includes that entire instance (including its
`PackageInstance` object) and its dependencies as well. Resources outside any
instance, such as `Namespace` and `CustomResourceDefinition` objects, are
included individually when needed.

Both `kix plan --only` and `kix deploy --only` show only the changes in the
current step:

- They list the selected instances alongside any required dependency instances
  that will also be deployed in full.
- They count the remaining changes compared with the active deployment:
  resources still to create or update, and resources removed from the build.
  Because that count compares the build against the active deployment record,
  earlier `--only` runs may already have applied some of those changes.
- Saved plans (`kix plan --only ... --out`) record the selected instances for
  `kix deploy --plan` (see [Deploy a reviewed plan](#deploy-a-reviewed-plan)).

A `--only` run leaves the cluster's `Active` deployment record unchanged. Kix
marks the new build's `Activation` record `Partial` and lists every deployed
instance (selected and required) in `status.partial`. Repeated `--only` runs
for the same build add their instances to `status.partial`. If the build you
pass to `--only` is already the cluster's active build, its record stays
`Active`.

Each `--only` deploy takes the [deploy lock](#the-deploy-lock), so concurrent
`--only` runs on the same cluster cannot overlap. Finishing a `--only` run
increments the lock generation (invalidating plans saved earlier) while
leaving the cluster's active deployment record unchanged on `ActivationHead`.

During a `--only` run, Kix does not delete removed resources, update the
list of kept orphans, or write a deploy receipt. When every selected resource succeeds, the
command exits `0` and prints a summary of what was deployed, what remains, and
the command to finish the rollout. `kix status` warns about any `Partial` or
`Failed` deployment records on the cluster.

When you are ready to finish, run `kix deploy <cluster>` without `--only` (add
`--prune` to delete removed resources). Kix folds in the changes from earlier
`Partial` runs, applies the rest of the build, marks the new record `Active`,
and marks earlier records `Superseded`. If your project files have changed
since the `--only` run, `kix deploy <cluster>` deploys the new build instead,
updating or reverting what `--only` applied as needed.

If a resource fails or the command is interrupted during `kix deploy --only`,
Kix marks the record `Failed` with `status.failure` and clears
`status.partial`. The next plan and deploy (with or without `--only`) include
any changes that run applied.

### Limits of `--only`

- **First deploy**: `--only` requires a cluster that Kix has already
  deployed in full, because the first deploy creates the initial active
  deployment record.
- **Operator-managed clusters**: `--only` is refused whenever the Kix operator
  deployed the cluster's active deployment record, whether someone ran
  `kix deploy --operator` or the record reached the operator another way (for
  example, applied from Git). The operator reconciles the active build and
  would revert partial changes. Deploy a full build first.
- **Flag combinations**: `--only` cannot be combined with `--prune` (a partial
  deploy never deletes resources) or `--operator` (the operator always deploys
  full builds). It works with `--dry-run`, `--plan`, `--bundle`, `--on-error`,
  and `--yes`. `kix rollback` does not support `--only`.

## Withdrawn releases

When a Kix release has a bug that can damage a cluster, kix.run marks it as
withdrawn in the signed release index, with the reason and the version to use
instead. `kix deploy` checks Kix's saved copy of the release index (refreshing
it from kix.run if it is more than a day old) and stops before applying
anything if the running version of Kix was withdrawn:

```text
Deploy blocked: Kix 0.10.1 was withdrawn because it deletes Secrets on rollback.
Nothing was applied to cluster dev.

Next: upgrade this project to Kix 0.10.2 with `kix upgrade --to 0.10.2`, then run `kix deploy dev` again.
To deploy with Kix 0.10.1 anyway, set KIX_ALLOW_WITHDRAWN=0.10.1. Kix will set kix.run/withdrawn-kix=0.10.1 on cluster dev's Activation record.
```

Setting `KIX_ALLOW_WITHDRAWN` to the exact withdrawn version lets the deploy
proceed and sets `kix.run/withdrawn-kix` to that version on the `Activation`
record.

`kix rollback` runs the same check (except with `--operator`, where the
operator runs its own version of Kix and the CLI only warns). `kix deploy
--dry-run`, `kix rollback --dry-run`, and other project commands such as `kix
plan` and `kix check` print a warning and continue. If Kix cannot reach
kix.run, it uses its last saved index. A machine that has never saved an index
deploys without this check.

## Examples

<Command commands={[
  "kix deploy demo --dry-run",
  "kix deploy demo --yes --prune --timeout 10m",
  "kix deploy demo --yes --log-format json",
]} />

`--log-format json` writes one JSON event object per line (NDJSON) to stdout,
while the plan, warnings, and confirmation text go to stderr. The first JSON
line has `"type": "kubernetes"` and identifies the target cluster with
`context` (the kubeconfig context) and `server` (its API server URL), each
`null` when not set in the kubeconfig. When the run
reaches the deploy engine, the last JSON line is the `summary` object, with
`succeeded` (which matches the exit status), `dry_run`, and the `created`,
`configured`, `unchanged`, `failed`, `cancelled`, `pruned`, and `kept` counts.
`pruned` counts only orphans deleted during this run, excluding orphans that
were already gone. `kept` counts orphans of this Kix cluster that `--prune`
left behind because an undeleted object depends on them (excluding objects
kept for another Kix cluster) or because their dependencies form a cycle. Each
is reported in a `prune_kept` event. Each
object is counted once by its final state: if Kix applies an object and it
does not become ready, Kix counts it in `failed` rather than `created` or
`configured`. The `summary` object also includes `failed_after_apply`, the
number of `failed` objects whose new manifest Kix applied before they failed
readiness. Text output shows this count as `1 failed (1 applied but not ready)`.
Runs that reach the deploy engine also set `"nothing_to_apply": false` on
`summary`.
With `--prune`, `summary` also includes `left_behind` when the new build no
longer declares a CustomResourceDefinition and custom resources of that kind
remain on the cluster after pruning (omitted when none remain). Each entry is
`{ kind, count, with_finalizers, objects }`, matching `left_behind` in the
[`Plan` document](/docs/reference/cli/plan/#the-plan-document). Other log
formats print a warning listing those objects after the summary line.
When the plan has nothing to apply or prune, Kix writes only the
`kubernetes` line and a `summary` line with `"nothing_to_apply": true`,
`"succeeded": true`, `unchanged` set to the number of unchanged objects, and
all other counts set to `0`. If the build has no resources, Kix does not
connect to the cluster and writes only that `summary` line, with
`"unchanged": 0`. Every
line includes `schema_version` (currently `"2026-11-27"`), the date of the
latest breaking change to the log format. For a deleted object
(`"kind": "delete"`), Kix emits the `ready` event only after the object is
removed from the cluster. If an object being pruned is already absent, its
`ready` event includes `"detail": {"already_gone": "already gone"}` (or
`"already gone (Kubernetes does not recognize its kind)"` when the cluster has
no API for that kind), and text output prints the same message instead of
`deleted`. A run
that stops before the engine starts, such as a refused plan or a failed
connection, writes no `summary` line; its error goes to stderr and the exit
status is non-zero.

## Exit status

| Code | Meaning |
| --- | --- |
| `0` | Deploy complete, nothing to apply, or the prompt was declined |
| `1` | A resource failed, under either `--on-error` mode, or the run was cancelled; `--prune` left orphans belonging to this cluster in place (`kept`); the plan showed a refused write under `--on-error stop`; a stateful migration was detected without `--accept-migrations`; confirmation was needed on a non-interactive terminal; the cluster would skip a [required stop](#required-stops); the cluster was [last deployed by a newer minor version of Kix](#deploys-by-an-older-kix); another run holds the [deploy lock](#the-deploy-lock) or modified the cluster after the plan was built; `kix-upgrade.json` lists a change to stored data for this cluster that no one has acknowledged with [`kix upgrade --acknowledge`](/docs/reference/cli/upgrade/#changes-to-stored-data); or a build, evaluation, or cluster error |

With `--dry-run` the exit status is [`kix plan`'s](/docs/reference/cli/plan/#exit-status):
`0` when nothing would change, `2` when something would, and `3` when the
deploy would stop.

:::tip[Use it in a task]
See [Deploy with dry-run, timeouts, pruning, and log or TUI output modes](/docs/how-to/operate-a-cluster/deploy-with-dry-run-timeouts-pruning-and-log-tui-output-modes/)
for the common flag combinations.
:::

:::note[Explanation]
See [The DAG-driven deployment scheduler](/docs/explanation/the-dependency-graph/#dag-driven-deployment-scheduler)
for how ordering, readiness, and pruning fit together.
:::