Kubernetes Operators and CRDs

CNPA Domain: Platform APIs and Provisioning Infrastructure (12%) Topics: Kubernetes Reconciliation Loop, APIs for Self-Service Platforms (CRDs), Kubernetes Operator Pattern for Integration, Infrastructure Provisioning with Kubernetes

Overview

Kubernetes operators and Custom Resource Definitions (CRDs) are how platform teams extend Kubernetes with domain-specific automation. Instead of writing runbooks and manual procedures, operators encode operational knowledge into code β€” continuously reconciling complex systems toward their desired state.


The Kubernetes Reconciliation Loop

Every Kubernetes controller operates on the same fundamental loop:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Reconciliation Loop                 β”‚
β”‚                                                  β”‚
β”‚  1. Watch API server for resource changes        β”‚
β”‚  2. Read current state from cluster              β”‚
β”‚  3. Compute diff: desired state vs actual state  β”‚
β”‚  4. Take action to close the gap                 β”‚
β”‚  5. Update resource status                       β”‚
β”‚  6. Back to step 1 (with backoff on errors)      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

This is how built-in controllers work (Deployment controller, Service controller) and it's exactly how custom operators work too.


Custom Resource Definitions (CRDs)

CRDs extend the Kubernetes API with your own resource types. They enable platform APIs β€” developers interact with Kubernetes objects that represent high-level platform concepts.

The platform operator translates this into the actual cloud provider calls.

Defining a CRD


The Operator Pattern

An operator = CRD + controller that automates operational tasks for a specific domain.

What Problem Do Operators Solve?

Manual Operations
With an Operator

Click through console to create DB

kubectl apply -f database.yaml

Write runbook for failover

Operator detects failure, runs failover automatically

Manual backup scheduling

Operator manages backup CronJobs

Complex upgrade procedures

kubectl edit database payment-db β†’ version: 16

Operator Maturity Levels (OperatorHub Model)


Crossplane: Infrastructure Provisioning via CRDs

Crossplanearrow-up-right takes the operator pattern to cloud infrastructure. It allows platform teams to expose cloud resources (AWS RDS, GCP Cloud SQL, Azure Service Bus) as Kubernetes CRDs.

Crossplane Architecture

Composite Resource Definition (XRD)


Building Operators: Tooling

Tool
Language
Notes

Operator SDK

Go, Ansible, Helm

CNCF project, batteries-included

Kubebuilder

Go

Lower-level, official sig-api-machinery tools

controller-runtime

Go

Library used by both above

kopf

Python

Kubernetes Operator Pythonic Framework

KUDO

YAML

Declarative operator framework

Minimum Operator Project (Kubebuilder)


CRDs for Self-Service Platform APIs

CRDs are the foundation of self-service platform APIs β€” developers use kubectl (or Backstage/a portal) to request platform capabilities:


Key Takeaways

  • The reconciliation loop is the core Kubernetes pattern: watch β†’ diff β†’ act β†’ repeat

  • CRDs extend the Kubernetes API with domain-specific resource types, enabling platform self-service APIs

  • Operators encode operational knowledge (install, upgrade, backup, failover) into running code

  • Crossplane uses the operator pattern to provision cloud infrastructure via declarative Kubernetes manifests

  • Developer-facing Composite Resources (XRDs + Compositions) hide cloud provider complexity behind clean APIs

  • Use Operator SDK or Kubebuilder to build Go-based operators; kopf for Python teams


Further Reading

Last updated