Operators and Custom Resources
Extend Kubernetes with Custom Resource Definitions and controllers that automate running complex software.
Advanced · about 8 hours · difficulty 4/5
Learn first: Packaging with Helm and Kustomize
Kubernetes is extensible: you can add your own object types (Custom Resource Definitions) and write controllers that reconcile them. An operator is a controller that encodes operational knowledge, such as how to provision, back up, upgrade and fail over a database.
What to understand
- CRDs define a new
kindwith a schema; custom resources are instances of it. - A controller watches resources and runs a reconcile loop: compare desired and actual state, take one step, requeue.
- Many tools you use are operators: cert-manager, Prometheus Operator, CloudNativePG, Strimzi (Kafka), Argo CD.
- Building your own: Kubebuilder or Operator SDK (Go), or lighter frameworks like kopf (Python).
- Status conditions, finalizers (cleanup before deletion) and owner references (garbage collection).
When to write one
Only when you have repeated, stateful operational logic that plain manifests and Helm cannot express. Most teams consume operators far more than they write them.
Pitfalls
Installing operators with cluster-wide permissions without review, and CRD upgrades that break existing resources.
Good enough to move on: you can install and operate a third-party operator, read its CRDs, and explain how its reconcile loop behaves when you edit a custom resource.
Key concepts
- Custom Resource Definitions
- Controllers and reconcile loops
- Finalizers and owner references
- Using existing operators
- Kubebuilder / Operator SDK
- kopf for Python
Mini project
Install the CloudNativePG operator, create a 3-instance Postgres cluster from a single custom resource, then delete the primary pod and watch the operator promote a replica.
Check yourself
What problem does a finalizer solve when a custom resource is deleted?
Free resources
- Operator pattern (kubernetes.io)
- The Kubebuilder Book (Kubernetes SIGs)