Stage 3 · Build
Kubernetes Controllers in Go
The Controller Pattern
Reconcile loop, informers, workqueues, and finalizers — the core of Kubernetes automation.
The Reconcile Loop
The controller pattern is the heart of Kubernetes. A controller watches resources and takes action to move the cluster toward the desired state. The reconcile loop compares desired state with actual state and takes corrective action.
Informers and Watches
Informers watch Kubernetes resources and maintain a local cache. When a resource changes, the informer fires an event that triggers the reconcile loop. This is more efficient than polling the API server.
Work Queues
Work queues serialize reconcile requests. They prevent duplicate processing, handle retries with exponential backoff, and rate-limit API server requests.
Every reconcile function must be idempotent — running it multiple times with the same input produces the same result. This is critical because controllers retry on errors and may reprocess the same event multiple times.
Finalizers
Finalizers let controllers clean up resources before they are deleted. When a resource has finalizers, Kubernetes sets the deletion timestamp instead of deleting it. The controller must remove the finalizer to complete deletion.
Error Handling and Requeueing
How you return from Reconcile determines what happens next. Different return values control requeueing, error handling, and timing.
Controller Anatomy
A complete controller consists of a reconciler struct, a Reconcile method, a SetupWithManager method, and registration with the manager.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.