Use this when applying Kubernetes resources declaratively.
Declarative Resources
Declarative resources describe the desired Kubernetes objects in YAML and apply them with kubectl apply or GitOps, letting the cluster reconcile toward that state instead of running imperative commands.
1. Declarative resources: apply desired state; Kubernetes reconciles.
2. Server-side apply tracks field ownership.
3. Avoid imperative kubectl edit in production.
4. Prune carefully.
5. GitOps for drift correction.
desired manifests → apply → controllers reconcile
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Verification path Verify boundary
The negative fixture should deliberately exercise risks such as schema drift, selector overreach, admission rejection, controller lag, immutable fields, stale status and confusing created object with ready workload, choosing the cases most relevant to desired object declarations, server-side validation/defaulting, generation/resourceVersion and controller reconciliation rather than imperative command history.
Step 2 Common mistakes Narrow the fault
- Mixing
kubectl editwith declarative apply.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Apply manifests with kubectl apply or GitOps.
- Server-side dry run validates against the cluster.
- kubectl diff shows changes.
kubectl apply --server-side -f manifests/— server-side applykubectl diff -f manifests/— preview- Field managers — ownership
ReferenceWhy it matters1 section · depth on demand
In depth
Kubernetes is declarative: you describe the desired state of resources, and controllers continuously work to make the cluster match it. You do not tell Kubernetes to start a container; you declare that a Deployment should have three replicas, and the controller creates, replaces or removes pods until that is true.
Consequences for automation:
kubectl applyis idempotent — applying the same manifest twice changes nothing.- Manual changes are overwritten when manifests are re-applied or reconciled by GitOps.
- Status (
.status) reports what the controller has achieved; the spec is what you asked for.
kubectl get deploy netbox-sync -o jsonpath='{.spec.replicas} {.status.readyReplicas}'
kubectl rollout status deploy/netbox-sync --timeout=120s
ReferenceImportant terms & boundaries1 section · depth on demand
Mechanics
The linked authority for bounded mechanics is Kubernetes Docs — Declarative Management of Kubernetes Objects; documentation support is separate from observed lab/production Evidence.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Kubernetes Automation > Declarative Resources. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://kubernetes.io/docs/tasks/manage-kubernetes-objects/declarative-config/ · confidence 94%Deep reference
Healthy vs suspicious evidence
Output interpretation
For desired object declarations, server-side validation/defaulting, generation/resourceVersion and controller reconciliation rather than imperative command history, prefer typed fields and stable IDs over human presentation text.