Capstone: GitOps and an operator
Put a custom resource under declarative management and verify the operator’s separate ownership of its children.
What you will understand
- Identify the fields owned by the declarative manager and the objects managed by the operator.
- Explain an intentional field conflict using managed fields.
- Prove repeatability, missing-child repair, and dependent cleanup in the same exercise.
Builds on: Ownership and failure recovery, GitOps and drift reconciliation, Capstone: recover stateful data
Declare a WebApp and derive its children
A platform user requests a web page called m20-platform with a message and one replica. The user needs a small declaration. The lab reconciler supplies a Deployment and ConfigMap. In this capstone, an apply manager called kv-gitops owns the WebApp specification. The operator reads the WebApp and derives the implementation resources. It manages their configuration and uses owner references to link them to that particular WebApp.
Trace the two responsibilities in the first scene. If the message changes, update the WebApp and let the operator propagate it. If a generated ConfigMap is deleted while the WebApp stays present, the operator can recreate it. This keeps the source of intent in a place the platform user can read and change.
Which writer owns the WebApp and its children?
The declarative manager writes the WebApp spec. The reconciler derives its ConfigMap and Deployment, links them to that WebApp, and publishes observed status.
Declare the WebApp
- kv-gitopsWebApp m20-platformSSA parent fields
kv-gitops applies the WebApp spec, establishing the intended page message and replica count.
Derive ConfigMap and Deployment
- WebApp m20-platformkv-webapp-operatorread desired intention
- kv-webapp-operatorDeployment + ConfigMapSSA generated fields
- WebApp m20-platformDeployment + ConfigMaplifecycle owner UID
The operator applies stable child names with its own field manager and the parent UID owner reference.
Report the observation separately
- kv-webapp-operatorWebApp statuspatch observed state
Status describes processed generation and observed ready count; GitOps acceptance is not synchronous application readiness.
The local GitOps role is modeled by kubectl SSA; a real Argo CD installation is optional.
Explore another case
Reproduce a field ownership conflict
The WebApp manifest is the declaration for this exercise. After applying it with kv-gitops, another apply manager called kv-human attempts to set a different value in an owned field. It should get a conflict. Inspect the management record and locate the field and owner. The chosen policy is to leave the original declaration in place.
apiVersion: labs.kv.example/v1alpha1
kind: WebApp
metadata:
name: m20-platform
namespace: kv-lab
labels:
lab: m20
spec:
replicas: 1
message: gitops-declared-pageVerify repeated reconciliation, repair, and deletion
Use a disposable cluster. The platform capstone script installs the CRD, applies the WebApp, runs the reconciler, checks the conflict and stable Deployment UID, deletes and repairs the ConfigMap, and finally deletes the parent. If you want to inspect the live resources, run the manual early steps after installing the CRD and before the script’s final delete. Record four observations: the conflict, stable UID during repeated passes, the recreated ConfigMap’s content, and disappearance of generated dependents after parent deletion.
# Run only the platform investigation from the downloaded m20 directory.
bash capstone-platform.sh
# To inspect before the script's final parent deletion, run its early steps manually:
kubectl --context kind-kv-lab -n kv-lab apply --server-side --field-manager=kv-gitops -f platform.yaml
python3 webapp-reconciler.py --iterations 2 --interval 1
kubectl --context kind-kv-lab -n kv-lab get webapp m20-platform -o yaml --show-managed-fields
kubectl --context kind-kv-lab -n kv-lab get deployment m20-platform -o yaml --show-managed-fieldsWhich resources should change during repeat, repair, and delete?
A repeated reconcile keeps the Deployment UID. A missing child is recreated. Deleting the parent allows garbage collection of its dependents.
Reconcile and compare UIDs
- WebApp parentReconcile passesdesired state
- Reconcile passesDeploymentrepeat apply
Multiple passes preserve Deployment UID when the desired child identity remains valid.
Recreate the deleted ConfigMap
- Reconcile passesConfigMaprepair missing child
Deleting the ConfigMap creates drift; another pass recreates current desired page content with a new child UID.
Delete the WebApp and observe cleanup
- WebApp parentGarbage collectorowner deletion
- Garbage collectorDeploymentcollect
- Garbage collectorConfigMapcollect
Removing the WebApp lets garbage collection remove its owned children; the operator does not recreate the absent parent.
The teaching controller manages only Kubernetes resources and supplies no external cleanup finalizer or production HA machinery.
Explore another case
Connect the exercise to production controllers
This capstone runs server-side apply and a local script. A production GitOps controller adds repository monitoring and policy, and a deployed operator needs watches, reliable retries, scoped permissions, and observability. The lab lets you verify the ownership model without needing either production component. Before adding persistent storage or external services, decide which parts of application state should remain when the WebApp is removed.
Check your understanding
The Deployment UID remained stable after several passes. Then the ConfigMap got a new UID after deletion. Can both outcomes be correct?
Yes. Repeated reconciliation left the existing Deployment in place. When the ConfigMap was missing, the operator created a new object for the same WebApp. Its data and owner reference show that the new child represents the current declaration.
Go to the source
- Server-side apply conflicts
- Operator pattern
- Owner references and garbage collection
- Argo CD automated sync
Reviewed 2026-10-27 · Kubernetes 1.37 · Related local exercise