kubernetes-operator-golang

Guides building production-grade Kubernetes Operators in Go with kubebuilder and controller-runtime.

Updated Apr 11, 2026
One-click install
npx skills add https://github.com/lurodrisilva/personal-skills --skill kubernetes-operator-golang-lurodrisilva
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: kubernetes-operator-golang
Source: https://github.com/lurodrisilva/personal-skills/tree/main/platform-engineering/kubernetes-operator-golang
Command: npx skills add https://github.com/lurodrisilva/personal-skills --skill kubernetes-operator-golang-lurodrisilva

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Building a Kubernetes Operator in Go involves many correctness pitfalls — non-idempotent reconcile loops, missing finalizers, status races, over-privileged RBAC, and broken OLM packaging. This Skill encodes the architectural rules, code patterns, and review gates needed to scaffold, implement, test, and package a correct operator on kubebuilder (go/v4) + controller-runtime + Operator SDK. ## Core Features & Use Cases - Full lifecycle guidance: Covers project scaffolding, CRD/API design (*_types.go, kubebuilder markers, OpenAPI + CEL validation, status conditions, multi-version conversion), the Reconcile loop (level-based, idempotent, CreateOrUpdate, owner references, finalizers, requeue strategy), admission webhooks, the manager entrypoint, least-privilege RBAC, envtest/Ginkgo testing, and OLM packaging (bundle, ClusterServiceVersion, opm File-Based Catalogs). - Non-negotiable core principles: Enforces level-based reconciliation, idempotency, declarative convergence, spec/status separation with the status subresource, operator-downtime isolation, finalizer-based external cleanup, and least privilege — plus the CNCF capability levels, four golden signals, and Seven Habits of Highly Successful Operators. - Use Case: You need to write an operator that manages a Memcached cluster. Use this Skill to scaffold the project with kubebuilder init, design the CRD with validation markers and status conditions, write an idempotent reconciler with SetControllerReference and finalizers, add envtest coverage, and generate an OLM bundle for distribution. ## Quick Start Ask the AI to scaffold a new Kubernetes operator in Go with kubebuilder for a custom resource, including the CRD types, an idempotent reconciler, RBAC markers, and an OLM bundle.

Frequently Asked Questions about kubernetes-operator-golang

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I build a Kubernetes operator in Go with kubebuilder?▼

Run kubebuilder init with your domain and repo, then kubebuilder create api to scaffold the CRD types and controller. Implement the Reconcile loop in internal/controller, regenerate artifacts with make generate and make manifests, and test with envtest before deploying.

How to write an idempotent reconcile loop with controller-runtime?▼

Use controllerutil.CreateOrUpdate keyed on a deterministic child name instead of blind Create calls, and call SetControllerReference so garbage collection and Owns watches work. Re-derive the full desired state every loop and return errors to trigger automatic requeue with backoff.

What is the difference between kubebuilder and Operator SDK?▼

Operator SDK is a kubebuilder-compatible wrapper that scaffolds the same go/v4 project layout and adds OLM packaging and scorecard tooling on top. The CRD, controller, and webhook workflows use identical plugins and flags.

When should I use a finalizer versus an owner reference in a Kubernetes operator?▼

Use owner references for in-cluster child resources so Kubernetes garbage collection deletes them with the owner. Use finalizers only when deletion requires external cleanup the garbage collector cannot do, such as cloud resources or backups, and add the finalizer before first acting.

Does this skill cover operating existing operators like Strimzi?▼

No, it covers building operators in Go only. Operating a third-party operator such as Strimzi is handled by the separate kafka-strimzi-operator skill, and Helm or Ansible adapter operators are out of scope.

Why does my operator break after upgrading from kubebuilder go/v3 to go/v4?▼

The go/v4 layout moved main.go to cmd/main.go, controllers/ to internal/controller/, and replaced MetricsBindAddress with the Metrics struct on ctrl.Options. Migrate with kubebuilder alpha generate or a fresh re-scaffold rather than manually moving files.