# Move from Flux to Kix in phases

You can move a Flux-managed cluster to Kix one layer at a time while your workloads stay up. Build a matching Kix definition beside your Flux repository, move each leaf layer on its own, clear Flux's server-side apply field ownership after each step, and move shared infrastructure and uninstall Flux last. This guide covers Flux only.

The examples below migrate a Flux repository into a Kix cluster named `test`. The Flux setup has three leaf layers (`web`, `podinfo`, and `api`) and one shared layer (`infra`). It uses `Kustomization` objects with `prune: true` and `dependsOn`, `HelmRelease` charts, `age`-encrypted SOPS secrets, and cluster variables from `postBuild.substitute` and `postBuild.substituteFrom`.

Kix has no pull-based sync inside the cluster today. Run `kix deploy` from a workstation or a CI job. Pull-based sync in the Kix operator is planned; today, [`kix deploy --operator`](/docs/reference/cli/operator-mode/) still builds and plans on your machine while the operator applies changes in the cluster.

## Keep Flux from deleting live objects

When you remove a file from Git during a migration, Flux either deletes or keeps the live Kubernetes objects according to six rules:

1. **Removing a `Kustomization` with `prune: true`:** When a parent `Kustomization` deletes a child `Kustomization` that sets `prune: true`, Flux deletes every object that child applied.
2. **Keeping a `Kustomization`'s objects:** Flux leaves those objects running if any one of three conditions holds before you remove the `Kustomization` from Git: you suspend it (`flux suspend kustomization <name>`), it sets `deletionPolicy: Orphan`, or the objects carry the annotation `kustomize.toolkit.fluxcd.io/prune: disabled`.
3. **Removing one object from a running `Kustomization`:** Flux deletes a removed object only while the live object still carries the `kustomize.toolkit.fluxcd.io/name` and `kustomize.toolkit.fluxcd.io/namespace` labels. Objects without those labels stay in the cluster.
4. **Removing a `HelmRelease`:** Deleting an active `HelmRelease` runs a Helm uninstall (`uninstalled Helm release for deleted resource` in `helm-controller` logs) and deletes the `Deployment`, `Service`, and release `Secret`. Suspend the `HelmRelease` first (`flux suspend helmrelease <name> -n <ns>`); `helm-controller` then logs `reconciliation is suspended for this object` on deletion and keeps the `Deployment`, `Service`, and release `Secret`.
5. **Removing a `Namespace` from a running shared layer:** Deleting a `Namespace` manifest from an active layer such as `infra` deletes that `Namespace` and everything inside it, including workloads Kix already manages. Add `kustomize.toolkit.fluxcd.io/prune: disabled` to the `Namespace` in Git and let Flux reconcile before you remove the manifest.
6. **Uninstalling Flux:** `flux uninstall` removes finalizers from every Flux object, then deletes the Flux CRDs and the `flux-system` `Namespace`. Objects inside `flux-system` (such as a `cluster-vars` `ConfigMap`) are deleted with that `Namespace`. Workloads and `Namespace` objects that Flux applied outside `flux-system` stay in place, even when their `Kustomization` was still active with `prune: true`.

## Build the Kix project next to the Flux repository

Create your Kix project beside your Flux checkout. Add one leaf layer at a time (`web`, `podinfo`, and `api`, which nothing else depends on) to `clusters/test.nix` as you migrate it, so Flux can keep reconciling the remaining layers. Move the shared `infra` layer last.

```nix title="clusters/test.nix"
{ kix, ... }:
let
  # What Flux read from the cluster-vars ConfigMap and postBuild.substitute.
  clusterVars = {
    clusterName = "kix-flux-test";
    environment = "production";
  };
in
kix.buildCluster {
  modules = [
    kix.flavors.kind
    {
      instances.web.web = {
        package = import ../packages/web.nix;
        # Keep the selector Flux created; Deployment selectors are immutable.
        selectorLabels.app = "web";
        config = {
          greeting = "Hello";
          inherit (clusterVars) clusterName environment;
          replicas = 2;
        };
      };

      instances.podinfo.podinfo = {
        package = kix.helmChart {
          repo = "https://stefanprodan.github.io/podinfo";
          name = "podinfo";
          version = "6.17.0";
          hash = "sha256-09Z/Rg+flLttEJUDFfwJU3me/A7mAzLjxHXnVemcDgQ=";
          releaseName = "podinfo";
        };
        # The values the HelmRelease set.
        config.values.replicaCount = 2;
      };

      instances.api.api = {
        package = import ../packages/api.nix;
        selectorLabels.app = "api";
        config.credentialsFile = ../secrets/api-credentials.enc.yaml;
      };
    }
  ];
}
```

### Replace `postBuild` variables and `dependsOn`

In the Flux repository, the `web` `Kustomization` set `postBuild.substitute: { GREETING: "Hello" }` and loaded `CLUSTER_NAME: kix-flux-test`, `ENVIRONMENT: production`, and `WEB_REPLICAS: "2"` from the `cluster-vars` `ConfigMap` through `postBuild.substituteFrom`. Manifests referenced those variables as `${GREETING} from ${CLUSTER_NAME}` in a `ConfigMap`, `${ENVIRONMENT}` in an environment variable, and `${WEB_REPLICAS}` for the replica count.

In `clusters/test.nix`, those variables become the `clusterVars` `let` binding and pass into typed options in `packages/web.nix`: `greeting`, `clusterName`, `environment` (an enum of `"staging"` and `"production"`), and `replicas` (a positive integer with default `2`). `packages/web.nix` builds the `web-content` `ConfigMap`, the `web` `Deployment`, and the `web` `Service`. Because options are typed, a typo fails `kix check` before deploy instead of producing an empty string. See [Create a local package](/docs/how-to/author-packages-and-clusters/create-a-local-package/) and [Add typed package options](/docs/how-to/author-packages-and-clusters/add-typed-package-options/).

You do not need Flux layers or `dependsOn` lists in Kix. Kix orders resources from the references between them: it applies a `Namespace` before the objects inside it, and applies a `Secret` before a `Deployment` that reads it through `out.mkEnv`. When you need an order that no reference expresses, see [Add explicit ordering with `extraDeps`](/docs/how-to/adopt-existing-resources/add-explicit-ordering-with-extradeps/).

### Check selectors and pod restarts before deploying

`Deployment` selectors are immutable. Set `selectorLabels` on each instance to keep the selector Flux used, as shown on `web` and `api` above. See [Preserve existing selectors](/docs/how-to/adopt-existing-resources/preserve-existing-selectors/).

Validate the cluster and render its manifests:

<Command
  commands={[
    "kix check test",
    "kix build test",
  ]}
/>

When Kix deploys a package for the first time, `kix plan test` lists the package as added (`+ web 1.0.0 (3 resources)`) and does not diff its fields against live objects on the cluster. Compare the `kix build test` output against the live YAML (`kubectl get ... -o yaml`) yourself before deploying.

Check for two pod-template differences that cause a one-time rollout during takeover:

- **Pod labels:** Kix adds `app.kubernetes.io/name` (set to the instance name) to the pod template of workloads such as `Deployment`s. Flux's `web` and `api` pods carried only `app: <name>`, so the first `kix deploy` updates their pod templates and rolls their pods once. With two replicas and a readiness probe, `web` keeps serving during the rollout, and none of the later cleanup steps restart the pods again. Pods that already carry a matching `app.kubernetes.io/name` label, such as `podinfo` (`app.kubernetes.io/name: podinfo`), do not restart at all.
- **Environment variable order:** `kix.mkEnvVars` and a `Secret`'s `out.mkEnv` sort container `env` entries alphabetically by variable name. If the Flux manifest listed those variables in another order, the first `kix deploy` updates the pod template and rolls the pods once.

## Move a Kustomization leaf layer (`web`)

Start with `instances.web.web` enabled in `clusters/test.nix` and follow these steps for each plain `Kustomization` leaf layer. See [Take ownership of kubectl-managed resources](/docs/how-to/adopt-existing-resources/take-ownership-of-kubectl-managed-resources/) for background on adopting existing objects.

1. Suspend the `web` `Kustomization` so Flux stops reconciling it:

   <Command commands={["flux suspend kustomization web"]} />

2. Check the plan and run a server-side dry run:

   <Command
     commands={[
       "kix plan test",
       "kix deploy test --dry-run",
     ]}
   />

   When Kix renders the same field values as Flux, server-side apply reports zero conflicts, so you do not need `--force-conflicts`.

3. Deploy with Kix and check workload health:

   <Command
     commands={[
       "kix deploy test",
       "kix status test",
       "kubectl rollout status deployment/web -n web",
     ]}
   />

   `kix deploy test` prints `Deploy complete: 5 created, 6 configured, 0 unchanged, 0 failed` (the five created resources are Kix's two CRDs and its `PackageInstance` records). Both `kustomize-controller` and `kix` now co-own the shared fields on `web`, and Flux's `kustomize.toolkit.fluxcd.io/*` labels remain on the objects.

4. Delete the `web` `Kustomization` from Git and push while `web` stays suspended. Flux deletes the suspended `Kustomization` object and leaves the `web` workloads running.

5. Clear `kustomize-controller` field ownership. As long as `kustomize-controller` co-owns fields on the adopted objects, Kix refuses later changes to those fields. Changing `replicas` from `2` to `3`, for example, stops on `kix deploy test --dry-run`:

   <Command commands={["kix deploy test --dry-run"]} />

   {/* Output in this guide is maintained by hand. It comes from a test run with Flux 2.10.0, which the docs capture pipeline cannot reproduce. */}

   ```text
   The deploy would stop on 1 write:
     ✗ Deployment.apps/web@web field ownership conflict
         kustomize-controller owns .spec.replicas
         --force-conflicts takes the fields; `ownership.cede` on the resource leaves them to the other manager
   ```

   :::note[Explanation]
   Flux's `kustomize-controller` applies as field manager `kustomize-controller`, `helm-controller` applies as `helm-controller`, and Kix applies as `kix`. Applying a minimal stub manifest under Flux's manager name removes that manager from `metadata.managedFields` and deletes any field that only Flux owned. Fields co-owned by `kix` stay in place. See [Server-side apply and drift](/docs/explanation/server-side-apply-and-drift/).
   :::

   Write a stub file containing only `apiVersion`, `kind`, `metadata.name`, and `metadata.namespace` for each object in the layer:

   ```yaml title="release-flux-web.yaml"
   apiVersion: apps/v1
   kind: Deployment
   metadata:
     name: web
     namespace: web
   ---
   apiVersion: v1
   kind: Service
   metadata:
     name: web
     namespace: web
   ---
   apiVersion: v1
   kind: ConfigMap
   metadata:
     name: web-content
     namespace: web
   ```

   Preview the apply with `--dry-run=server -o yaml` first to check whether any Flux-only field you still need would be deleted, then apply the stub file:

   <Command
     commands={[
       "kubectl apply --server-side --field-manager=kustomize-controller -f release-flux-web.yaml --dry-run=server -o yaml",
       "kubectl apply --server-side --field-manager=kustomize-controller -f release-flux-web.yaml",
     ]}
   />

   This removes `kustomize-controller` from `managedFields` and strips the `kustomize.toolkit.fluxcd.io/name` and `kustomize.toolkit.fluxcd.io/namespace` labels without restarting pods. Later edits to `replicas` plan cleanly.

6. Check every object with `--reconcile` to confirm that no expected field was lost:

   <Command commands={["kix plan test --reconcile"]} />

   `Plan: 5 unchanged` confirms that every live object matches Kix's output. If the plan shows a missing field, restore it with `kix deploy test --reconcile`.

## Move a HelmRelease layer (`podinfo`)

Enable `instances.podinfo.podinfo` in `clusters/test.nix` to migrate the `podinfo` chart. For the general Helm adoption workflow, see [Take ownership of Helm-managed resources](/docs/how-to/adopt-existing-resources/take-ownership-of-helm-managed-resources/).

1. Save the live Helm values and manifest so you can compare them against Kix's output:

   <Command
     commands={[
       "helm get values podinfo --namespace podinfo --all --output yaml > podinfo.values.yaml",
       "helm get manifest podinfo --namespace podinfo > podinfo.manifest.yaml",
     ]}
   />

2. Pin the same chart `version`, `releaseName`, and `config.values` with `kix.helmChart` in `clusters/test.nix`. To find `hash`, set `sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=` in `clusters/test.nix` and run `kix check test`:

   <Command commands={["kix check test"]} />

   ```text
   the Helm chart podinfo 6.17.0 from https://stefanprodan.github.io/podinfo has the hash sha256-09Z/Rg+flLttEJUDFfwJU3me/A7mAzLjxHXnVemcDgQ=, but the package expects sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=.
   ```

   Copy the reported digest into `hash` and run `kix check test` again.

3. Suspend the `HelmRelease`:

   <Command commands={["flux suspend helmrelease podinfo -n podinfo"]} />

4. Run a server-side dry run:

   <Command commands={["kix deploy test --dry-run"]} />

   ```text
   The deploy would stop on 2 writes:
     ✗ Deployment.apps/podinfo@podinfo field ownership conflict
         helm-controller owns .metadata.labels.app.kubernetes.io/managed-by
         --force-conflicts takes the fields; `ownership.cede` on the resource leaves them to the other manager
     ✗ Service/podinfo@podinfo field ownership conflict
         helm-controller owns .metadata.labels.app.kubernetes.io/managed-by
         --force-conflicts takes the fields; `ownership.cede` on the resource leaves them to the other manager
   ```

   This conflict is expected because Helm sets `app.kubernetes.io/managed-by: Helm` while Kix sets `app.kubernetes.io/managed-by: kix`. See [Handle server-side-apply conflicts safely](/docs/how-to/adopt-existing-resources/handle-server-side-apply-conflicts-safely/).

5. Deploy once with `--force-conflicts` to take over the label, then check workload status:

   <Command
     commands={[
       "kix deploy test --force-conflicts",
       "kix status test",
       "kubectl rollout status deployment/podinfo -n podinfo",
     ]}
   />

   No pods restart. Do not pass `--force-conflicts` on later deploys.

6. Keep the `HelmRelease` suspended, leave the `podinfo` `Kustomization` active, and delete the `HelmRelease`, its `HelmRepository`, and the `podinfo` `Kustomization` from Git in the same commit. The active `Kustomization` deletes the `HelmRelease` and `HelmRepository` objects from the cluster, and `helm-controller` skips the uninstall because the `HelmRelease` was suspended.

7. Delete the Helm release `Secret`:

   <Command commands={["kubectl -n podinfo delete secret -l owner=helm,name=podinfo"]} />

   :::caution
   Never run `helm uninstall` to remove the release record. `helm uninstall` deletes the live `Deployment` and `Service` along with the release `Secret`.
   :::

8. Write `release-flux-podinfo.yaml` with `Deployment` and `Service` stubs in `podinfo`, preview and apply it under `--field-manager=helm-controller`, and verify with `--reconcile`:

   <Command
     commands={[
       "kubectl apply --server-side --field-manager=helm-controller -f release-flux-podinfo.yaml --dry-run=server -o yaml",
       "kubectl apply --server-side --field-manager=helm-controller -f release-flux-podinfo.yaml",
       "kix plan test --reconcile",
     ]}
   />

   Clearing `helm-controller` removes the `helm.sh/chart` label, `helm.toolkit.fluxcd.io/*` labels, and `meta.helm.sh/*` annotations without restarting pods.

## Move a layer with SOPS secrets (`api`)

In `packages/api.nix`, `scope.mkSecret { name = "api-credentials"; keys = [ "username" "password" ]; source = ./secrets/api-credentials.enc.yaml; }` keeps the secret file encrypted in Git and in Kix's local store. `kix deploy` runs `sops --decrypt` right before applying the `Secret`, ahead of the `Deployment` that reads it. See [Use SOPS-backed secrets](/docs/how-to/platform-capabilities/use-sops-backed-secrets-if-production-ready/).

### Convert the Flux SOPS file first

Flux encrypts a complete Kubernetes `Secret` manifest. Kix expects a SOPS file that decrypts to a flat key-value map.

:::caution
If you pass Flux's encrypted `Secret` manifest to `scope.mkSecret`, `kix plan` and `kix deploy` stop with error `[K6746]` naming the `metadata` key before applying that `Secret`. The `Secret` on the cluster is left unchanged. Follow the steps below to convert the Flux SOPS file before you run `kix deploy`, and see [Convert a SOPS file from Flux](/docs/how-to/platform-capabilities/use-sops-backed-secrets-if-production-ready/#convert-a-sops-file-from-flux) for a general description.
:::

1. Add a creation rule in `.sops.yaml` for Kix's secret files without `encrypted_regex`. A Flux repository usually sets `encrypted_regex: ^(data|stringData)$`, which leaves flat keys such as `username` and `password` in plain text:

   ```yaml title=".sops.yaml"
   creation_rules:
     - path_regex: secrets/.*\.enc\.yaml$
       age: <your age recipient>
   ```

   Replace `<your age recipient>` with your `age` public key.

2. On a trusted machine, point `SOPS_AGE_KEY_FILE` at the `age` key Flux used, extract `stringData` into a flat file, and encrypt that file in place right away (the `sops decrypt` command writes plain values to disk briefly until `sops encrypt` overwrites it):

   <Command
     commands={[
       "export SOPS_AGE_KEY_FILE=/path/to/age.agekey",
       `sops decrypt --extract '["stringData"]' apps/api/credentials.sops.yaml > secrets/api-credentials.enc.yaml`,
       "sops encrypt --in-place secrets/api-credentials.enc.yaml",
     ]}
   />

   Open `secrets/api-credentials.enc.yaml` before committing and confirm that `username` and `password` show `ENC[...]` values.

### Adopt `api` and clear Flux field ownership

1. Enable `instances.api.api` in `clusters/test.nix`, suspend the `api` `Kustomization`, run a dry run, and deploy:

   <Command
     commands={[
       "export SOPS_AGE_KEY_FILE=/path/to/age.agekey",
       "flux suspend kustomization api",
       "kix deploy test --dry-run",
       "kix deploy test",
       "kix status test",
       "kubectl rollout status deployment/api -n api",
     ]}
   />

   `kix deploy test` decrypts and writes both keys (`Secret/api-credentials@api> hydrated 2 keys from SOPS` in line-log output). Delete the `api` `Kustomization` from Git while it stays suspended.

2. Clear `kustomize-controller` field ownership on the `api` resources.

   Kix writes `Secret` values under `data`, so after `kix deploy test`, both `kix` and `kustomize-controller` own every key in `api-credentials`. Applying the stub manifest removes `kustomize-controller`, and the keys stay in place because Kix still owns them.

   Preview `release-flux-api.yaml` with `--dry-run=server -o yaml` first and check that `api-credentials` still holds `username` and `password` under `data`. Then apply the stub file and verify with `kix plan test --reconcile`:

   <Command
     commands={[
       "kubectl apply --server-side --field-manager=kustomize-controller -f release-flux-api.yaml --dry-run=server -o yaml",
       "kubectl apply --server-side --field-manager=kustomize-controller -f release-flux-api.yaml",
       "kix plan test --reconcile",
     ]}
   />

   If `data` disappears in the preview, an earlier version of Kix deployed `api-credentials` through the write-only `stringData` field and does not own `data` yet. Run `kix deploy test --reconcile` so Kix rewrites the `Secret` and takes ownership under `data`, then run the preview again before applying the stub file.

## Detach Namespaces from `infra` and uninstall Flux

### Remove a Namespace from a running shared layer

If you want to remove a `Namespace` (such as `web`) from `infra` while `infra` keeps reconciling, block pruning on that `Namespace` first:

1. Add `kustomize.toolkit.fluxcd.io/prune: disabled` to the `web` `Namespace` in `infra/namespaces.yaml` in Git and let Flux reconcile:

   ```yaml title="infra/namespaces.yaml"
   apiVersion: v1
   kind: Namespace
   metadata:
     name: web
     annotations:
       kustomize.toolkit.fluxcd.io/prune: disabled
   ```

2. Confirm that the live `Namespace` has the annotation:

   <Command commands={["kubectl get namespace web -o yaml"]} />

3. Remove the `web` `Namespace` document from `infra/namespaces.yaml` in Git and let `infra` reconcile. Flux leaves the `web` `Namespace` and Kix's workloads untouched.

4. Clear `kustomize-controller` ownership from the `web` `Namespace` with a `Namespace` stub manifest (`release-flux-web-ns.yaml`). Because Flux owned the `kustomize.toolkit.fluxcd.io/prune: disabled` annotation, the empty apply removes that annotation too:

   <Command
     commands={[
       "kubectl apply --server-side --field-manager=kustomize-controller -f release-flux-web-ns.yaml --dry-run=server -o yaml",
       "kubectl apply --server-side --field-manager=kustomize-controller -f release-flux-web-ns.yaml",
     ]}
   />

### Uninstall Flux

Once every workload layer runs under Kix and nothing reads `cluster-vars` in `flux-system`, remove Flux from the cluster:

1. Preview `flux uninstall` with `--dry-run`, then run it:

   <Command
     commands={[
       "flux uninstall --dry-run",
       "flux uninstall",
     ]}
   />

   `flux uninstall` strips finalizers from every Flux resource, deletes the Flux CRDs, and deletes `flux-system` (including `cluster-vars`). Everything `infra` applied outside `flux-system`, including the `podinfo` and `api` `Namespace` objects and their workloads, stays in place.

2. Clear `kustomize-controller` field ownership from any remaining objects Flux applied (in this example, the `podinfo` and `api` `Namespace` objects) using stub manifests previewed with `--dry-run=server -o yaml`.

3. Run a final reconcile check and status check:

   <Command
     commands={[
       "kix plan test --reconcile",
       "kix status test",
     ]}
   />

   `kix plan test --reconcile` prints `Plan: 5 unchanged`, and `kix status test` reports every resource healthy:

   ```text
     api/api                         3 resources  ok
     kube-system/platform-dns        1 resource   ok
     kube-system/platform-storage    1 resource   ok
     podinfo/podinfo                 3 resources  ok
     web/web                         4 resources  ok
     (cluster-level)                 6 resources  ok

   18 resources: 18 ok.
   ```

## Optional: export YAML for Flux to apply

If you want Kix to compile manifests while Flux keeps applying them, export plain YAML into your Flux repository checkout (see [Export plain YAML](/docs/how-to/operate-a-cluster/export-plain-yaml/)). For a Kix cluster named `bridge`, run from the Flux checkout:

<Command commands={["kix export bridge --out apps/bridge"]} />

`kix export` writes one YAML file per object without `kix.run/*` annotations or `Activation` and `PackageInstance` records, ready for a Flux `Kustomization` to apply. Because Flux applies the manifests in this mode, Kix's readiness waits, deploy records, and rollback do not run.

Before committing `apps/bridge`, delete `_cluster/Namespace-kube-system.yaml`. If Flux applies that file and you later remove that `Kustomization` from Git with pruning enabled, Flux tries to delete `kube-system`. The Kubernetes API server refuses that deletion, which leaves the `Kustomization` stuck until you suspend it.

Exported objects keep the label `app.kubernetes.io/managed-by: kix`. If you deploy a Kix cluster (such as `test`) to the same Kubernetes cluster, `kix gc --full-scan` sees that Kix did not apply those Flux-managed objects. It lists them under "Copied labels" and keeps them unless you pass `--include copies`:

<Command commands={["kix gc test --full-scan --dry-run"]} />