How-to guide / Adopt existing resources
Move from Flux to Kix in phases
These docs describe Kix's main branch, which can include changes not yet released. Read the docs for the latest release.
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 still builds and plans on your machine while the operator applies changes in the cluster.
Keep Flux from deleting live objects
Section titled “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:
- Removing a
Kustomizationwithprune: true: When a parentKustomizationdeletes a childKustomizationthat setsprune: true, Flux deletes every object that child applied. - Keeping a
Kustomization’s objects: Flux leaves those objects running if any one of three conditions holds before you remove theKustomizationfrom Git: you suspend it (flux suspend kustomization <name>), it setsdeletionPolicy: Orphan, or the objects carry the annotationkustomize.toolkit.fluxcd.io/prune: disabled. - Removing one object from a running
Kustomization: Flux deletes a removed object only while the live object still carries thekustomize.toolkit.fluxcd.io/nameandkustomize.toolkit.fluxcd.io/namespacelabels. Objects without those labels stay in the cluster. - Removing a
HelmRelease: Deleting an activeHelmReleaseruns a Helm uninstall (uninstalled Helm release for deleted resourceinhelm-controllerlogs) and deletes theDeployment,Service, and releaseSecret. Suspend theHelmReleasefirst (flux suspend helmrelease <name> -n <ns>);helm-controllerthen logsreconciliation is suspended for this objecton deletion and keeps theDeployment,Service, and releaseSecret. - Removing a
Namespacefrom a running shared layer: Deleting aNamespacemanifest from an active layer such asinfradeletes thatNamespaceand everything inside it, including workloads Kix already manages. Addkustomize.toolkit.fluxcd.io/prune: disabledto theNamespacein Git and let Flux reconcile before you remove the manifest. - Uninstalling Flux:
flux uninstallremoves finalizers from every Flux object, then deletes the Flux CRDs and theflux-systemNamespace. Objects insideflux-system(such as acluster-varsConfigMap) are deleted with thatNamespace. Workloads andNamespaceobjects that Flux applied outsideflux-systemstay in place, even when theirKustomizationwas still active withprune: true.
Build the Kix project next to the Flux repository
Section titled “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.
1{ kix, ... }:2let3 # What Flux read from the cluster-vars ConfigMap and postBuild.substitute.4 clusterVars = {5 clusterName = "kix-flux-test";6 environment = "production";7 };8in9kix.buildCluster {10 modules = [11 kix.flavors.kind12 {13 instances.web.web = {14 package = import ../packages/web.nix;15 # Keep the selector Flux created; Deployment selectors are immutable.16 selectorLabels.app = "web";17 config = {18 greeting = "Hello";19 inherit (clusterVars) clusterName environment;20 replicas = 2;21 };22 };23
24 instances.podinfo.podinfo = {25 package = kix.helmChart {26 repo = "https://stefanprodan.github.io/podinfo";27 name = "podinfo";28 version = "6.17.0";29 hash = "sha256-09Z/Rg+flLttEJUDFfwJU3me/A7mAzLjxHXnVemcDgQ=";30 releaseName = "podinfo";31 };32 # The values the HelmRelease set.33 config.values.replicaCount = 2;34 };35
36 instances.api.api = {37 package = import ../packages/api.nix;38 selectorLabels.app = "api";39 config.credentialsFile = ../secrets/api-credentials.enc.yaml;40 };41 }42 ];43}Replace postBuild variables and dependsOn
Section titled “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 and 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.
Check selectors and pod restarts before deploying
Section titled “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.
Validate the cluster and render its manifests:
❱ 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 asDeployments. Flux’swebandapipods carried onlyapp: <name>, so the firstkix deployupdates their pod templates and rolls their pods once. With two replicas and a readiness probe,webkeeps serving during the rollout, and none of the later cleanup steps restart the pods again. Pods that already carry a matchingapp.kubernetes.io/namelabel, such aspodinfo(app.kubernetes.io/name: podinfo), do not restart at all. - Environment variable order:
kix.mkEnvVarsand aSecret’sout.mkEnvsort containerenventries alphabetically by variable name. If the Flux manifest listed those variables in another order, the firstkix deployupdates the pod template and rolls the pods once.
Move a Kustomization leaf layer (web)
Section titled “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 for background on adopting existing objects.
-
Suspend the
webKustomizationso Flux stops reconciling it:❱ flux suspend kustomization web -
Check the plan and run a server-side dry run:
❱ kix plan test❱ kix deploy test --dry-runWhen Kix renders the same field values as Flux, server-side apply reports zero conflicts, so you do not need
--force-conflicts. -
Deploy with Kix and check workload health:
❱ kix deploy test❱ kix status test❱ kubectl rollout status deployment/web -n webkix deploy testprintsDeploy complete: 5 created, 6 configured, 0 unchanged, 0 failed(the five created resources are Kix’s two CRDs and itsPackageInstancerecords). Bothkustomize-controllerandkixnow co-own the shared fields onweb, and Flux’skustomize.toolkit.fluxcd.io/*labels remain on the objects. -
Delete the
webKustomizationfrom Git and push whilewebstays suspended. Flux deletes the suspendedKustomizationobject and leaves thewebworkloads running. -
Clear
kustomize-controllerfield ownership. As long askustomize-controllerco-owns fields on the adopted objects, Kix refuses later changes to those fields. Changingreplicasfrom2to3, for example, stops onkix deploy test --dry-run:❱ kix deploy test --dry-run1The deploy would stop on 1 write:2✗ Deployment.apps/web@web field ownership conflict3kustomize-controller owns .spec.replicas4--force-conflicts takes the fields; `ownership.cede` on the resource leaves them to the other managerWrite a stub file containing only
apiVersion,kind,metadata.name, andmetadata.namespacefor each object in the layer:release-flux-web.yaml 1apiVersion: apps/v12kind: Deployment3metadata:4name: web5namespace: web6---7apiVersion: v18kind: Service9metadata:10name: web11namespace: web12---13apiVersion: v114kind: ConfigMap15metadata:16name: web-content17namespace: webPreview the apply with
--dry-run=server -o yamlfirst to check whether any Flux-only field you still need would be deleted, then apply the stub file:❱ 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.yamlThis removes
kustomize-controllerfrommanagedFieldsand strips thekustomize.toolkit.fluxcd.io/nameandkustomize.toolkit.fluxcd.io/namespacelabels without restarting pods. Later edits toreplicasplan cleanly. -
Check every object with
--reconcileto confirm that no expected field was lost:❱ kix plan test --reconcilePlan: 5 unchangedconfirms that every live object matches Kix’s output. If the plan shows a missing field, restore it withkix deploy test --reconcile.
Move a HelmRelease layer (podinfo)
Section titled “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.
-
Save the live Helm values and manifest so you can compare them against Kix’s output:
❱ helm get values podinfo --namespace podinfo --all --output yaml > podinfo.values.yaml❱ helm get manifest podinfo --namespace podinfo > podinfo.manifest.yaml -
Pin the same chart
version,releaseName, andconfig.valueswithkix.helmChartinclusters/test.nix. To findhash, setsha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=inclusters/test.nixand runkix check test:❱ kix check test1the 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
hashand runkix check testagain. -
Suspend the
HelmRelease:❱ flux suspend helmrelease podinfo -n podinfo -
Run a server-side dry run:
❱ kix deploy test --dry-run1The deploy would stop on 2 writes:2✗ Deployment.apps/podinfo@podinfo field ownership conflict3helm-controller owns .metadata.labels.app.kubernetes.io/managed-by4--force-conflicts takes the fields; `ownership.cede` on the resource leaves them to the other manager5✗ Service/podinfo@podinfo field ownership conflict6helm-controller owns .metadata.labels.app.kubernetes.io/managed-by7--force-conflicts takes the fields; `ownership.cede` on the resource leaves them to the other managerThis conflict is expected because Helm sets
app.kubernetes.io/managed-by: Helmwhile Kix setsapp.kubernetes.io/managed-by: kix. See Handle server-side-apply conflicts safely. -
Deploy once with
--force-conflictsto take over the label, then check workload status:❱ kix deploy test --force-conflicts❱ kix status test❱ kubectl rollout status deployment/podinfo -n podinfoNo pods restart. Do not pass
--force-conflictson later deploys. -
Keep the
HelmReleasesuspended, leave thepodinfoKustomizationactive, and delete theHelmRelease, itsHelmRepository, and thepodinfoKustomizationfrom Git in the same commit. The activeKustomizationdeletes theHelmReleaseandHelmRepositoryobjects from the cluster, andhelm-controllerskips the uninstall because theHelmReleasewas suspended. -
Delete the Helm release
Secret:❱ kubectl -n podinfo delete secret -l owner=helm,name=podinfo -
Write
release-flux-podinfo.yamlwithDeploymentandServicestubs inpodinfo, preview and apply it under--field-manager=helm-controller, and verify with--reconcile:❱ 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 --reconcileClearing
helm-controllerremoves thehelm.sh/chartlabel,helm.toolkit.fluxcd.io/*labels, andmeta.helm.sh/*annotations without restarting pods.
Move a layer with SOPS secrets (api)
Section titled “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.
Convert the Flux SOPS file first
Section titled “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.
-
Add a creation rule in
.sops.yamlfor Kix’s secret files withoutencrypted_regex. A Flux repository usually setsencrypted_regex: ^(data|stringData)$, which leaves flat keys such asusernameandpasswordin plain text:.sops.yaml 1creation_rules:2- path_regex: secrets/.*\.enc\.yaml$3age: <your age recipient>Replace
<your age recipient>with youragepublic key. -
On a trusted machine, point
SOPS_AGE_KEY_FILEat theagekey Flux used, extractstringDatainto a flat file, and encrypt that file in place right away (thesops decryptcommand writes plain values to disk briefly untilsops encryptoverwrites it):❱ 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.yamlOpen
secrets/api-credentials.enc.yamlbefore committing and confirm thatusernameandpasswordshowENC[...]values.
Adopt api and clear Flux field ownership
Section titled “Adopt api and clear Flux field ownership”-
Enable
instances.api.apiinclusters/test.nix, suspend theapiKustomization, run a dry run, and deploy:❱ 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 apikix deploy testdecrypts and writes both keys (Secret/api-credentials@api> hydrated 2 keys from SOPSin line-log output). Delete theapiKustomizationfrom Git while it stays suspended. -
Clear
kustomize-controllerfield ownership on theapiresources.Kix writes
Secretvalues underdata, so afterkix deploy test, bothkixandkustomize-controllerown every key inapi-credentials. Applying the stub manifest removeskustomize-controller, and the keys stay in place because Kix still owns them.Preview
release-flux-api.yamlwith--dry-run=server -o yamlfirst and check thatapi-credentialsstill holdsusernameandpasswordunderdata. Then apply the stub file and verify withkix plan test --reconcile:❱ 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 --reconcileIf
datadisappears in the preview, an earlier version of Kix deployedapi-credentialsthrough the write-onlystringDatafield and does not owndatayet. Runkix deploy test --reconcileso Kix rewrites theSecretand takes ownership underdata, then run the preview again before applying the stub file.
Detach Namespaces from infra and uninstall Flux
Section titled “Detach Namespaces from infra and uninstall Flux”Remove a Namespace from a running shared layer
Section titled “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:
-
Add
kustomize.toolkit.fluxcd.io/prune: disabledto thewebNamespaceininfra/namespaces.yamlin Git and let Flux reconcile:infra/namespaces.yaml 1apiVersion: v12kind: Namespace3metadata:4name: web5annotations:6kustomize.toolkit.fluxcd.io/prune: disabled -
Confirm that the live
Namespacehas the annotation:❱ kubectl get namespace web -o yaml -
Remove the
webNamespacedocument frominfra/namespaces.yamlin Git and letinfrareconcile. Flux leaves thewebNamespaceand Kix’s workloads untouched. -
Clear
kustomize-controllerownership from thewebNamespacewith aNamespacestub manifest (release-flux-web-ns.yaml). Because Flux owned thekustomize.toolkit.fluxcd.io/prune: disabledannotation, the empty apply removes that annotation too:❱ 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
Section titled “Uninstall Flux”Once every workload layer runs under Kix and nothing reads cluster-vars in flux-system, remove Flux from the cluster:
-
Preview
flux uninstallwith--dry-run, then run it:❱ flux uninstall --dry-run❱ flux uninstallflux uninstallstrips finalizers from every Flux resource, deletes the Flux CRDs, and deletesflux-system(includingcluster-vars). Everythinginfraapplied outsideflux-system, including thepodinfoandapiNamespaceobjects and their workloads, stays in place. -
Clear
kustomize-controllerfield ownership from any remaining objects Flux applied (in this example, thepodinfoandapiNamespaceobjects) using stub manifests previewed with--dry-run=server -o yaml. -
Run a final reconcile check and status check:
❱ kix plan test --reconcile❱ kix status testkix plan test --reconcileprintsPlan: 5 unchanged, andkix status testreports every resource healthy:1api/api 3 resources ok2kube-system/platform-dns 1 resource ok3kube-system/platform-storage 1 resource ok4podinfo/podinfo 3 resources ok5web/web 4 resources ok6(cluster-level) 6 resources ok7818 resources: 18 ok.
Optional: export YAML for Flux to apply
Section titled “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). For a Kix cluster named bridge, run from the Flux checkout:
❱ 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:
❱ kix gc test --full-scan --dry-run