Skip to main content
Kubernetes internalsLesson 4 of 12

CRDs and Operators

Built-in Kubernetes resources have no concept like "a database" or "a nightly backup". So you register a new resource kind (CRD) and attach a program that handles it (an operator). Most tools, such as Istio (service mesh), Velero (backup) and the NVIDIA GPU Operator, are built on this pattern. The Database below is an example resource for illustration.

Database kindUnknown
CR status—
Child resources—
UserkubectlAPI serverentry for resourcesCRDregisters a kindshop-dbDatabase CROperatorDB controllerStatefulSetDB PodsServiceconnection addressSecretDB passwordDatabase?
RequestResponse / reportWatchAppears in a later step

What you will learn

  • CRD (definition) vs CR (actual resource)
  • Why a CRD alone does nothing
  • How an operator runs ops knowledge in a reconcile loop
  • Deleting a CRD deletes all its CRs

Working back from the symptom​

SymptomLikely causeWhat to check
A CR was created hours ago and status is still emptyNo controller (operator) to handle it, or it is stoppedWhether the controller Pod runs, its logs, the CR's events
After upgrading a tool, saving with new fields is rejectedHelm did not update the CRD, so the old schema remainsThe CRD update steps in the tool's upgrade guide
After removing a tool, the namespace never leaves TerminatingThe operator that clears CR finalizers was deleted firstFinalizers on the remaining CRs
All backup schedules disappeared at onceA CRD deletion removed every CR of that kindHistory of tool removal and upgrades

Try it yourself​

kubectl get crd # Registered resource kinds
kubectl api-resources --api-group=<group> # Served like built-in resources
kubectl explain <kind>.spec # Schema the CRD registered
kubectl get pods -A | grep -i <operator> # Is the operator handling it running?
kubectl describe <kind> <name> -n <namespace> # Status conditions and events

Check yourself

  1. You created a Database CR hours ago and its status is still empty. What should you check first?
  2. How does an operator differ from installing with Helm?
  3. While cleaning up a tool, someone deletes its CRD. What happens?

Further reading: Custom resources · Operator pattern · Velero · Why deletion gets stuck: Deletion Is More Complex Than You Think