Operators and CRDs
CRDs extend the Kubernetes API with new types. Operators are controllers that reconcile those types.
Operators package operational knowledge as code. They turn "the on-call runbook for Postgres" into a controller that runs in your cluster.
CRD: a new type in the API
A CustomResourceDefinition tells the API server "from now on, accept and store objects of kind PostgresCluster." You can kubectl get postgresclusters just like Pods. The API server handles storage, validation (via OpenAPI schema), versioning. No code required for the CRD itself.
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata: { name: postgresclusters.db.example.com }
spec:
group: db.example.com
names: { kind: PostgresCluster, plural: postgresclusters }
scope: Namespaced
versions:
- name: v1
served: true
storage: true
schema: { openAPIV3Schema: { ... } }Operator: the controller behind the CRD
The CRD by itself is inert. You write a controller (the Operator) that watches the CRD, diffs desired vs actual, takes action. Same reconcile loop pattern as the built-in controllers.
The operator creates whatever underlying resources are needed (StatefulSets, Services, ConfigMaps), monitors them, handles failover, backups, version upgrades.
When to use an operator
- Stateful systems with complex lifecycle: databases, message brokers, search clusters. cert-manager, Postgres Operator (CrunchyData, Zalando), Strimzi (Kafka), Elastic Cloud on Kubernetes.
- Domain-specific platforms: ArgoCD (continuous delivery), Tekton (pipelines), Crossplane (cloud resources).
- Internal platform abstractions: your platform team exposes
kind: Microservicethat creates Deployment + Service + Ingress + ServiceMonitor with sensible defaults.
When NOT to build one
- You just want to template some YAML. Use Helm or Kustomize.
- You want a one-time setup. Use a Job.
- The behavior is stateless and well-modeled by built-ins.
Frameworks
- controller-runtime / Kubebuilder: Go, the reference path.
- Operator SDK: thin wrapper over Kubebuilder with extras.
- Metacontroller: write controllers as webhooks in any language.
The interview answer
CRDs extend the API with new types. Operators are controllers that reconcile those types. Use them for stateful complexity (databases, brokers) or to expose platform abstractions. Not for templating YAML - that is Helm.
Learn more
- DocsCustom Resourceskubernetes.io
- DocsOperator patternkubernetes.io
- DocsOperator SDKsdk.operatorframework.io