Skip to main content

CRDs & Operators

Key Takeaways for AI & Readers
  • API Extensibility: Custom Resource Definitions (CRDs) allow you to add your own object types (like Database or Certificate) to the Kubernetes API.
  • The Operator Pattern: Combining a CRD with a custom Controller creates an "Operator," which automates the management of complex applications.
  • Operational Automation: Operators encode domain-specific knowledge (e.g., how to back up a database or rotate keys) directly into the cluster's logic.
  • Standard Tooling: Custom resources work seamlessly with existing tools like kubectl once registered.

Kubernetes is extensible. You aren't limited to Pods, Services, and Deployments. You can create your own resources!

1. Custom Resource Definitions (CRDs)

A CRD allows you to extend the Kubernetes API with your own types.

Kubernetes API

Pod
Service
Deployment
(Empty Slot for New API)

Once you register a CRD (like Pizza), kubectl acts as if it's a native object:

  • kubectl get pizzas
  • kubectl describe pizza/pepperoni

2. Controllers & Operators

A CRD by itself stores data (like a database entry), but it doesn't do anything. To make it active, you need a Controller.

CRD + Custom Controller = Operator

Example: The Prometheus Operator

  1. CRD: You define a resource kind: ServiceMonitor.
  2. Controller: A Go program running in the cluster watches for ServiceMonitor files.
  3. Action: When you create a ServiceMonitor, the Controller detects it and automatically reconfigures the Prometheus server config file to scrape the new target.

Why use Operators?

They encode "Human Operational Knowledge" into software.

  • Database Operator: Knows how to take backups, handle failover, and resize clusters automatically.