Skip to main content
In this lesson we’ll cover how to develop a Kubernetes custom controller (also called an operator) to act on Custom Resources such as a FlightTicket CRD. You already created a CustomResourceDefinition (CRD) and stored FlightTicket objects in etcd. A controller watches those objects and performs actions (for example, calling an external flight booking API to book, modify, or cancel tickets).

Example: FlightTicket CR

Example FlightTicket manifest:
Create the resource and verify it exists:
CRDs don’t automatically display a STATUS column in kubectl get output. Controllers usually populate fields under .status. Inspect status with: kubectl get flightticket my-flight-ticket -o yaml or add custom printer columns in the CRD to show status in kubectl get.

What is a controller?

A controller is a process (or set of processes) that runs a reconcile loop: it watches the Kubernetes API for changes to specific objects and reacts to those events. For FlightTicket objects, a controller might:
  • Call the external Flight Booking API when a new ticket is requested
  • Update the resource’s .status with booking state (confirmed, failed, pending)
  • Retry operations on transient errors
  • Clean up resources when tickets are canceled
You can implement controllers in any language, but Go is the most common choice because the official Kubernetes client libraries provide reusable components that handle caching, event delivery, and retries.

Why Go and client-go?

Using the Go client libraries (for example, k8s.io/client-go) gives you well-tested building blocks:
  • Shared Informers: efficient event delivery and local caching
  • Workqueues: rate-limited queues with retries
  • Listers: fast reads from the local cache
These primitives let you focus on business logic (the flight booking flow) rather than implementing queueing and cache correctness yourself.

Starting point — sample-controller

A widely used example project is the kubernetes/sample-controller repository. Typical workflow:
  1. Clone the repository.
  2. Modify the controller implementation (e.g., controller.go) to add your domain logic (call the Flight Booking API when FlightTicket objects are created/updated).
  3. Build the controller binary.
  4. Run it locally using your kubeconfig or build a container image and deploy it inside the cluster.
Clone and build the sample controller:
A slide titled "Custom Controller" showing a screenshot of the GitHub repository "kubernetes/sample-controller." The page displays the repo's file list, branch/tag info, and sidebar details like contributors and license.
Example commands and build/run flow:
Inside a Go controller you will typically see declarations and function signatures like:
When the controller runs (locally or inside the cluster), it watches creation/update/deletion events for FlightTicket objects and executes the logic you implemented: calling the booking API, updating CR status, and retrying on failures.

Key controller components (quick reference)

Tip: use kubebuilder or operator-framework tooling to scaffold scaffolding, CRD + controller wiring, and RBAC boilerplate quickly.

Packaging and deployment

When your controller works, package it as a container image and deploy it to the cluster (commonly as a Deployment). Running controllers inside the cluster simplifies authentication (in-cluster config) and benefits from Kubernetes’ scheduling and lifecycle management.
Run controllers inside the cluster as a Deployment or DaemonSet (depending on your needs). This simplifies authentication (in-cluster config) and provides high availability and lifecycle management.

Exam note

Implementing controllers requires development work and is usually beyond the scope of basic Kubernetes administration exams. Exams commonly test:
  • Creating and using CustomResourceDefinitions (CRDs)
  • Inspecting resources and their .status
  • Understanding controller behavior at a high level (CRD → controller watches resources → controller acts → status updated)
Understanding the high-level flow is important even if you are not expected to write production-quality controllers in the exam. That’s all for now.

Watch Video