Back to Blog
KubernetesGoDevOps

Building Kubernetes Operators with Go

2026-03-30·9 min read

What are Operators?

Kubernetes Operators are software extensions that use custom resources to manage applications and their components. They encode operational knowledge — how to deploy, scale, upgrade, and recover — into automated controllers.

The Control Loop

Every Kubernetes controller follows the same reconciliation loop:

  • **Observe**: Watch for changes to desired and actual state
  • **Diff**: Compare desired vs actual state
  • **Act**: Take actions to reconcile the difference
  • func (r *MyAppReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
        myApp := &v1alpha1.MyApp{}
        if err := r.Get(ctx, req.NamespacedName, myApp); err != nil {
            return ctrl.Result{}, client.IgnoreNotFound(err)
        }
        
        // Reconcile logic here
        return ctrl.Result{RequeueAfter: 30 * time.Second}, nil
    }

    Custom Resource Definitions

    CRDs extend the Kubernetes API with new resource types. Define your schema using OpenAPI v3 and the API server handles validation, versioning, and storage.

    Testing Operators

    Use envtest to run a real API server and etcd locally for integration testing. For unit tests, fake clients simulate the Kubernetes API without infrastructure.

    Conclusion

    Operators are the gold standard for running stateful applications on Kubernetes. They transform tribal knowledge into code, making complex systems reliably self-managing.

    Thanks for reading! Share this if it helped.

    More articles →