# `export`

`kix export` builds the cluster's activation and writes each resource to its
own YAML file. It does not contact a cluster. By default it writes plain
Kubernetes YAML with no Kix annotations or Kix-internal resources, which
`kubectl`, Flux, or Argo CD can apply. With `--with-kix-metadata` it keeps
everything as evidence of what Kix would deploy.

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

## Synopsis

```text
kix export <CLUSTER> [--out <DIR>] [--with-kix-metadata] [--force]
           [--flake <FLAKE>]
```

| Argument or flag | Default | Meaning |
| --- | --- | --- |
| `<CLUSTER>` | | Cluster name to build. |
| `--out <DIR>` | `./kix-export` | Directory to write. |
| `--with-kix-metadata` | Off | Keep the `kix.run/*` annotations and Kix's own records. See [What is kept](#what-is-kept). |
| `--force` | Off | Replace an existing output directory. See [Overwriting](#overwriting). |
| `--flake <FLAKE>` | `.` | Flake to build. |

`-o` has no effect. Progress and the summary line go to stderr; `-q` hides
them. See [Global flags](/docs/reference/cli/global-flags/) for
`--override-input`.

## What is kept

| | `kix.run/*` annotations | Activation and PackageInstance resources |
| --- | --- | --- |
| Default | Removed | Skipped |
| `--with-kix-metadata` | Kept, including the identity hash and package stamps a deploy writes | Written |

Every export drops null fields and writes keys in sorted order. Labels are
written unchanged.

## Layout

Each resource is written to `<DIR>/<namespace>/<Kind>-<name>.yaml`.
Cluster-scoped resources go under `<DIR>/_cluster/`. An export written with
`--with-kix-metadata` is a valid baseline for
[`kix diff --from`](/docs/reference/cli/diff/#baseline); a default export is
not, because the diff needs the Kix annotations.

## Overwriting

Without `--force`, an existing output directory is an error. With `--force`,
Kix deletes the directory and writes it again, so files from an earlier export
do not linger. It refuses when the directory holds anything other than
subdirectories and `.yaml` files, or a symlink, and names the first such entry.

## Examples

<Command commands={[
  "kix export demo --out handoff/",
  "kubectl diff --server-side -R -f handoff/",
  "kix export demo --with-kix-metadata --out evidence/ --force",
]} />

## Exit status

`0` on success, `1` when the build fails or the output directory cannot be
written or replaced.

:::tip[Use it in a task]
See [Export plain YAML](/docs/how-to/operate-a-cluster/export-plain-yaml/)
and [Export audit-preserving YAML](/docs/how-to/operate-a-cluster/export-audit-preserving-yaml/).
:::