Custom Resource Definitions (CRDs) & Extending the Kubernetes API
Extend the API with CRDs so platforms expose domain-specific resources.
In plain words
A CRD is a custom form registered at city hall; the controller is the department that later acts on filed requests. The simple Kubernetes rule is: CRDs publish new API types with OpenAPI schemas, versions, defaulting, and optionally conversion, letting users create domain resources through the same API machinery.
Think of it like…
A CRD is a custom form registered at city hall; the controller is the department that later acts on filed requests.
Where you’ve seen it
A platform team reviews a promoted source revision and runs kubectl get crd; kubectl explain database.spec --recursive; kubectl get database -A. Expected evidence: CRDs publish new API types with OpenAPI schemas, versions, defaulting, and optionally conversion, letting users create domain resources through the same API machinery. If the run instead shows this symptom, stop and restore the last known state: Loose preserveUnknownFields behavior and unversioned schema changes can accept invalid data, while deleting a CRD also deletes every custom object of its kind.
Words you’ll hear
- CRD
- For this lesson, CRD is the controlling idea: CRDs publish new API types with OpenAPI schemas, versions, defaulting, and optionally conversion, letting users create domain resources through the same API machinery.
- API Extension
- API Extension is the checkpoint; run
kubectl get crd; kubectl explain database.spec --recursive; kubectl get database -Aand inspect the owner chain. Loose preserveUnknownFields behavior and unversioned schema changes can accept invalid data, while deleting a CRD also deletes every custom object of its kind. - Custom Resources
- Custom Resources is the outcome to preserve; the cost is explicit: CRDs let platforms expose domain concepts, but API compatibility, plural naming, status conventions, pruning, and CRD lifecycle become a long-term product contract.
- Verification evidence
- The evidence command is
kubectl get crd; kubectl explain database.spec --recursive; kubectl get database -A. It connects the declaration to this behavior: Extend the API with CRDs so platforms expose domain-specific resources.
Visual diagram
Theory & deep dive
How CRD reaches the intended state
Extend the API with CRDs so platforms expose domain-specific resources. CRDs publish new API types with OpenAPI schemas, versions, defaulting, and optionally conversion, letting users create domain resources through the same API machinery.
The concrete checkpoint is kubectl get crd; kubectl explain database.spec --recursive; kubectl get database -A; compare the CRD owner, API Extension state, and Custom Resources outcome instead of treating YAML acceptance as proof.
Run kubectl get crd; kubectl explain database.spec --recursive; kubectl get database -A after the change and correlate the result with Events and the owning object. CRDs publish new API types with OpenAPI schemas, versions, defaulting, and optionally conversion, letting users create domain resources through the same API machinery.
API Extension: failure boundary and production cost
Loose preserveUnknownFields behavior and unversioned schema changes can accept invalid data, while deleting a CRD also deletes every custom object of its kind. The prerequisite contract is concrete: CRDs publish new API types with OpenAPI schemas, versions, defaulting, and optionally conversion, letting users create domain resources through the same API machinery.
CRDs let platforms expose domain concepts, but API compatibility, plural naming, status conventions, pruning, and CRD lifecycle become a long-term product contract. A safe design limits blast radius, records the last good configuration, and uses kubectl get crd; kubectl explain database.spec --recursive; kubectl get database -A as a deterministic rollback checkpoint.
Capture the current state with kubectl get crd; kubectl explain database.spec --recursive; kubectl get database -A, then correct the controlling manifest rather than patching a child object; the relevant divergence signal is specific: Loose preserveUnknownFields behavior and unversioned schema changes can accept invalid data, while deleting a CRD also deletes every custom object of its kind.
How it works, step by step
Step 1 of 41. Choose the source of truth
Version the source and describe the review, render, and reconciliation boundary: CRDs publish new API types with OpenAPI schemas, versions, defaulting, and optionally conversion, letting users create domain resources through the same API machinery.
- Goal
- Extend the API with CRDs so platforms expose domain-specific resources.
- Owner
- CRD
When to use it & trade-offs
What it is
Extend the API with CRDs so platforms expose domain-specific resources. CRDs publish new API types with OpenAPI schemas, versions, defaulting, and optionally conversion, letting users create domain resources through the same API machinery.
Why it matters: Loose preserveUnknownFields behavior and unversioned schema changes can accept invalid data, while deleting a CRD also deletes every custom object of its kind. The invariant at risk is specific: CRDs publish new API types with OpenAPI schemas, versions, defaulting, and optionally conversion, letting users create domain resources through the same API machinery. The quickest fact check before changing the design is kubectl get crd; kubectl explain database.spec --recursive; kubectl get database -A.
When to reach for it
- Use CRD to enforce this invariant: CRDs publish new API types with OpenAPI schemas, versions, defaulting, and optionally conversion, letting users create domain resources through the same API machinery.
- Use API Extension evidence from
kubectl get crd; kubectl explain database.spec --recursive; kubectl get database -Ain reviews and incident timelines. Extend the API with CRDs so platforms expose domain-specific resources. - Choose the platform operator workflow route only when this cost is justified by governance or scale: CRDs let platforms expose domain concepts, but API compatibility, plural naming, status conventions, pruning, and CRD lifecycle become a long-term product contract.
When to avoid or be careful
- Avoid assuming CRD is complete after YAML submission; the required behavior is concrete: CRDs publish new API types with OpenAPI schemas, versions, defaulting, and optionally conversion, letting users create domain resources through the same API machinery.
- Avoid treating the next symptom as random; check the owner and state with
kubectl get crd; kubectl explain database.spec --recursive; kubectl get database -Afirst: Loose preserveUnknownFields behavior and unversioned schema changes can accept invalid data, while deleting a CRD also deletes every custom object of its kind. - Avoid adopting a heavier platform wrapper before measuring its cost: CRDs let platforms expose domain concepts, but API compatibility, plural naming, status conventions, pruning, and CRD lifecycle become a long-term product contract.
Native, manual, and managed paths for CRD
kubectl get crd; kubectl explain database.spec --recursive; kubectl get database -A.Strengths: CRDs publish new API types with OpenAPI schemas, versions, defaulting, and optionally conversion, letting users create domain resources through the same API machinery.
Watch out: CRDs let platforms expose domain concepts, but API compatibility, plural naming, status conventions, pruning, and CRD lifecycle become a long-term product contract. Recovery must also recognize this signal: Loose preserveUnknownFields behavior and unversioned schema changes can accept invalid data, while deleting a CRD also deletes every custom object of its kind.
kubectl get crd; kubectl explain database.spec --recursive; kubectl get database -A; the expected invariant is: CRDs publish new API types with OpenAPI schemas, versions, defaulting, and optionally conversion, letting users create domain resources through the same API machinery.Strengths: kubectl get crd; kubectl explain database.spec --recursive; kubectl get database -A gives immediate feedback without first building a platform layer.
Watch out: A manual change can hide drift, and unlike CRD, it does not make this symptom self-documenting: Loose preserveUnknownFields behavior and unversioned schema changes can accept invalid data, while deleting a CRD also deletes every custom object of its kind.
kubectl get crd; kubectl explain database.spec --recursive; kubectl get database -A.Strengths: Platform controls can wrap this exact behavior in policy or dashboards: CRDs publish new API types with OpenAPI schemas, versions, defaulting, and optionally conversion, letting users create domain resources through the same API machinery.
Watch out: The added platform ownership buys value at this cost: CRDs let platforms expose domain concepts, but API compatibility, plural naming, status conventions, pruning, and CRD lifecycle become a long-term product contract.
Interview signals & numbers to know
When this topic comes up
- Interview anchor: CRDs publish new API types with OpenAPI schemas, versions, defaulting, and optionally conversion, letting users create domain resources through the same API machinery.
- Trace CRD to Custom Resources through API Extension; the invariant is: CRDs publish new API types with OpenAPI schemas, versions, defaulting, and optionally conversion, letting users create domain resources through the same API machinery.
- Recognize the symptom: Loose preserveUnknownFields behavior and unversioned schema changes can accept invalid data, while deleting a CRD also deletes every custom object of its kind.
- Justify the cost: CRDs let platforms expose domain concepts, but API compatibility, plural naming, status conventions, pruning, and CRD lifecycle become a long-term product contract.
- Verify with kubectl get crd; kubectl explain database.spec --recursive; kubectl get database -A instead of only inspecting YAML.
Benchmarks & rules of thumb
- 1
- API resource identity must survive each storage version
- 2
- CRD subresources commonly used are status and scale
- 0
- controller behavior is supplied automatically by defining a schema
Common mistakes & follow-ups
Common interview mistakes
- Debugging only the child object misses the CRD owner contract: CRDs publish new API types with OpenAPI schemas, versions, defaulting, and optionally conversion, letting users create domain resources through the same API machinery.
- Ignoring this telltale condition leads to unrelated changes: Loose preserveUnknownFields behavior and unversioned schema changes can accept invalid data, while deleting a CRD also deletes every custom object of its kind.
- Repeating
kubectl get crd; kubectl explain database.spec --recursive; kubectl get database -Awithout an owner for remediation wastes retry cost. CRDs let platforms expose domain concepts, but API compatibility, plural naming, status conventions, pruning, and CRD lifecycle become a long-term product contract.
Likely interviewer follow-ups
- How would API output and runtime evidence prove this behavior: CRDs publish new API types with OpenAPI schemas, versions, defaulting, and optionally conversion, letting users create domain resources through the same API machinery?
- Which owner object, logs, and Events would you inspect for this symptom-Loose preserveUnknownFields behavior and unversioned schema changes can accept invalid data, while deleting a CRD also deletes every custom object of its kind-?
- At what threshold would this cost become unacceptable: CRDs let platforms expose domain concepts, but API compatibility, plural naming, status conventions, pruning, and CRD lifecycle become a long-term product contract?
kubectl get crd; kubectl explain database.spec --recursive; kubectl get database -A, name the failure, then justify the cost. Invariant: CRDs publish new API types with OpenAPI schemas, versions, defaulting, and optionally conversion, letting users create domain resources through the same API machinery. Failure: Loose preserveUnknownFields behavior and unversioned schema changes can accept invalid data, while deleting a CRD also deletes every custom object of its kind. Cost: CRDs let platforms expose domain concepts, but API compatibility, plural naming, status conventions, pruning, and CRD lifecycle become a long-term product contract.Knowledge check
Put it into practice
Practice related interview Q&A
Apply Custom Resource Definitions (CRDs) & Extending the Kubernetes API with generative AI interview Q&A and hands-on practice.