CKAD — Operator Pattern

1 minute read

The Operator Pattern

A CRD defines the what — the data structure. An Operator provides the how — the logic that acts on custom resources.

How Operators Work

An Operator is a controller that:

  1. Watches for changes to custom resources
  2. Takes action based on the desired state
  3. Updates the status of the custom resource
┌──────────────┐    watches    ┌──────────────┐
│  Custom       │ ←──────────── │  Operator     │
│  Resource     │               │  Controller   │
│  (desired     │ ──────────── →│  (creates/    │
│   state)      │   reconciles  │   manages     │
└──────────────┘               │   resources)  │
                               └──────────────┘
                                     │
                                     ▼
                        ┌──────────────────────┐
                        │  Pods, Services,      │
                        │  ConfigMaps, etc.     │
                        └──────────────────────┘

Real-World Operator Examples

Operator Custom Resource What It Does
cert-manager Certificate Automatically requests and renews TLS certificates
Prometheus PrometheusRule Configures monitoring alerts
Strimzi Kafka Manages Kafka clusters on Kubernetes
CloudNativePG Cluster Manages PostgreSQL clusters

Using an Operator (cert-manager Example)

You do not need to build Operators for the CKAD exam. But you should understand how to use them.

# Once cert-manager is installed, you create a Certificate resource:
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: my-tls
  namespace: default
spec:
  secretName: my-tls-secret
  issuerRef:
    name: letsencrypt-prod
    kind: ClusterIssuer
  dnsNames:
  - myapp.example.com

The cert-manager Operator watches this resource and:

  1. Requests a certificate from Let’s Encrypt
  2. Creates a Secret with the TLS certificate
  3. Automatically renews before expiry

Finding Installed CRDs and Operators

# List all CRDs in the cluster
kubectl get crd

# Check which CRDs belong to a specific operator
kubectl get crd | grep cert-manager
# Example output:
# certificates.cert-manager.io
# clusterissuers.cert-manager.io
# issuers.cert-manager.io

# List instances of a custom resource
kubectl get certificates

# Check the operator controller is running
kubectl get pods -n cert-manager

Next: CRD vs ConfigMap →

Updated: