Interview's MateKubernetes
Interview's Mate

Kubernetes

K8s · Workloads · GitOps · Cloud

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Kubernetes topics
Lesson 98/ 160
05. Configuration, Packaging & GitOps

Custom Resource Definitions (CRDs) & Extending the Kubernetes API

Extend the API with CRDs so platforms expose domain-specific resources.

AdvancedCRD · API Extension · Custom Resources3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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 -A and 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

Loading interactive 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.

Verify API Extension, not only object creation

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.

Key takeaway: CRD is implemented only when this invariant remains observable: 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.

Recover from API Extension drift

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.

Key takeaway: Accept the trade-off consciously: CRDs let platforms expose domain concepts, but API compatibility, plural naming, status conventions, pruning, and CRD lifecycle become a long-term product contract.

How it works, step by step

Step 1 of 4
Source author

1. 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.

CRD contract → owned state
Key numbers at this step
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 -A in 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 -A first: 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

Versioned declarative source
Best for: Extend the API with CRDs so platforms expose domain-specific resources. A concrete incident check is 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.

Imperative cluster edit
Best for: Quickly testing the API Extension assumption with 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.

Platform operator workflow
Best for: Teams that need Custom Resources integrated with guardrails; the evidence path is 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 -A without 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?
Interview tip: Interview sequence: state the invariant, run 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

Loading quiz

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.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Multi-Environment Promotion Strategies (Dev → Staging → Prod)
Next topic
Kubernetes Operators & The Controller Reconciliation Loop (Kubebuilder / Operator SDK)