How-to guide / Adopt existing resources
Take ownership of kubectl-managed resources
These docs describe Kix's main branch, which can include changes not yet released. Read the docs for the latest release.
Use a one-time server-side apply takeover when an existing resource was
applied with kubectl and should now be managed by Kix.
This guide uses a Deployment as the example. Back up the live resource first, and perform the takeover during a normal change window.
Record the live resource
Section titled “Record the live resource”Save the resource before changing its ownership:
❱ kubectl get deployment legacy-web -n takeover -o yaml --show-managed-fields > legacy-web.before.yaml Keep any fields your workload relies on, especially immutable selectors,
Service selectors, volume claims, and identity-bearing names. The
managedFields section also shows which manager owns each part of the object.
Make the Kix definition match
Section titled “Make the Kix definition match”Configure the package instance with the live Deployment’s selector and the state you want Kix to manage:
22 instances.takeover.legacy-web = {23 package = webPackage;24
25 # Keep the live Deployment's immutable selector.26 selectorLabels = {27 app = "legacy-web";28 tier = "frontend";29 };30
31 config = {32 replicas = 2;33 environment = "production";34 message = "This workload is managed by Kix";35 };36 };The example retains the existing app and tier selector. Its desired replica
count is two, while the kubectl-managed fixture has one replica.
Check the cluster before contacting Kubernetes:
❱ kix check how-to-adoption-takeover
TOOL RESULT DETAILS
eval pass 9 manifests evaluated
scorecard pass 0 errors, 6 warnings, 1 info
governance.hasOwner (warning), 1:
takeover/legacy-web: package 'legacy-web' has no meta.owner
reliability.boundedResources (warning), 1:
takeover/legacy-web/legacy-web: container 'nginx' is missing resource settings: limits.cpu. Set CPU and memory requests and limits.
reliability.hasProbes (warning), 1:
takeover/legacy-web/legacy-web: container 'nginx' has no livenessProbe
security.hasNetworkPolicy (warning), 1:
takeover: namespace 'takeover' has workloads but no network policy
security.nonRoot (warning), 1:
takeover/legacy-web/legacy-web: container 'nginx' may run as root: neither it nor the pod sets securityContext.runAsNonRoot, and no non-zero runAsUser resolves for it
security.readOnlyRootfs (warning), 1:
takeover/legacy-web/legacy-web: container 'nginx' does not set readOnlyRootFilesystem
1 info finding(s) not listed; run with -v to list them. Inspect the rendered Deployment:
❱ kix build how-to-adoption-takeover --output json
{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"name": "legacy-web",
"namespace": "takeover"
},
"spec": {
"replicas": 2,
"selector": {
"matchLabels": {
"app": "legacy-web",
"tier": "frontend"
}
},
"template": {
"metadata": {
"labels": {
"app": "legacy-web",
"app.kubernetes.io/name": "legacy-web",
"tier": "frontend"
}
},
"spec": {
"containers": [
{
"name": "nginx",
"image": "docker.io/library/nginx:1.27-alpine"
}
]
}
}
}
} Compare it with legacy-web.before.yaml. Do not continue if the rendered
resource changes an immutable selector or omits a field the workload still
needs. Correct the package configuration first.
Confirm the ownership conflict
Section titled “Confirm the ownership conflict”Run an API-server dry run without taking ownership:
❱ kix deploy how-to-adoption-takeover --dry-run -y Show outputHide output · 5 lines
The deploy would stop on 1 write:
✗ Deployment.apps/legacy-web@takeover field ownership conflict
kubectl owns .spec.replicas
--force-conflicts takes the fields; `ownership.cede` on the resource leaves them to the other manager
(exit code: 3) Kix discovers live state through its management labels, so
kix plan --read-only does not compare a resource that Kix has not managed before. The deployment dry run
sends the intended manifests to the API server without persisting them.
The API server rejects a change when another field manager owns a field Kix is
trying to change. The error identifies the resource and points to
--force-conflicts.
The dry run carries on past a conflict, so the plan lists every conflicting
resource with the manager that owns each field. Review every reported field
against the saved resource before using --force-conflicts.
Take ownership once
Section titled “Take ownership once”When the diff and conflicting fields are expected, deploy with
--force-conflicts:
❱ kix deploy how-to-adoption-takeover --force-conflicts -y
~ Deployment.apps/legacy-web@takeover configured
… Deployment.apps/legacy-web@takeover waiting: Deployment/legacy-web: 0/2 updated pods ready, 2 old pods still running; pod legacy-web-747f558dff-qsb5h/nginx is waiting: ContainerCreating (idle 0s) (14s of 180s); 3 objects wait for it: Service/legacy-web@takeover and 2 more
✔ Deployment.apps/legacy-web@takeover ready
• activation 'how-to-adoption-takeover-1wv1i1x4fclp' → Active
Deploy complete: 5 created, 4 configured, 0 unchanged, 0 failed The flag tells server-side apply to transfer conflicting fields in the Kix
manifest to the Kix cluster’s field manager, kix/<cluster>. Fields that Kix does not specify remain
with their existing managers.
Check the result and save its field ownership:
❱ kix status how-to-adoption-takeover❱ kubectl get deployment legacy-web -n takeover -o yaml --show-managed-fields > legacy-web.after.yaml Use ordinary kix deploy how-to-adoption-takeover commands after the takeover.
Do not leave --force-conflicts enabled for routine deployments, because a
later conflict may represent another controller making an intentional change.