# Reconcile drift

A standard `kix deploy` heals out-of-band changes automatically. It recreates
any resource in the build that is missing from the cluster or being deleted,
and it restores fields that another writer changed on a Kix-applied resource,
taking ownership back from that field manager. `kix plan` marks those resources
as changed on the cluster before anything is applied. Pass `--reconcile` only
when you want Kix to reapply every resource in the build regardless of whether
it changed.

{/* The `kix status` output below is maintained by hand until the live
    captures how-to/application-drift/scaled-deployment and
    how-to/application-reconcile/drift-clean in docs/nix/captures.nix are
    regenerated. */}

## Review what changed

Start by finding the objects that changed and the fields that changed on
them:

<Command commands={["kix status how-to-application --check drift"]} cwd="kix-examples/" />

```text
...
how-to-app/production
  Deployment how-to-app/production  changed since deploy (spec.replicas by kubectl)

16 resources: 15 ok, 1 changed.
Next: run `kix deploy how-to-application` to restore what is missing or changed, or `kix plan how-to-application` to preview the changes first. The deploy takes back the fields that kubectl owns.
```

Run `kix plan how-to-application` to preview what the deploy will change. The
plan counts drifted resources on a `↺` line and lists each modified field and
its current field manager under `Drift:`.

Confirm that the checked-in cluster definition still describes the state you
want. Reconciliation applies that definition, so review intentional emergency
changes before continuing.

## Reapply the desired resources

The example output shows that `kubectl` changed `spec.replicas`. Deploy the
cluster to restore the field and take ownership back:

<Command expandable {...reconcileApplication} />

The example begins with a production Deployment that was scaled from two
replicas to one outside Kix. `kix deploy` reapplies that Deployment with force
and waits for it to become ready, leaving unchanged resources untouched.

Use `--context` and `--flake` when the Kubernetes target or source directory
is not the current one:

<Command
  commands={[
    "kix deploy how-to-application -y --flake ./infrastructure --context kind-kix-demo",
  ]}
/>

Omit `-y` when running interactively if you want to review the confirmation
prompt.

## Confirm the result

Run the drift check again:

<Command commands={["kix status how-to-application --check drift"]} cwd="kix-examples/" />

```text
...
16 resources: 16 ok.
```

No object should be changed, and the command exits `0`. Run `kix status`
without `--check` to also confirm that the reapplied workloads are ready. See
[Check a cluster's status](/docs/how-to/operate-a-cluster/check-resource-status/).

Fields listed in `ownership.cede` never count as changed, so `kix deploy`
leaves them with the controller that owns them. Kix also never forces fields
away from another Kix cluster. If two Kix clusters set different values for the
same field, the deploy stops with `[K5636]`. `--reconcile` reapplies every
resource in the build, and `--force-conflicts` forces field ownership on every
apply. Neither flag is needed to heal drift.