ScriptsApr 15, 2026·3 min read

Kubebuilder — SDK for Building Kubernetes APIs and Operators

Kubebuilder is a framework for building Kubernetes APIs using Custom Resource Definitions. It scaffolds an idiomatic controller-runtime project, manages code generation, and gives you the tooling to publish a production-grade operator.

TL;DR
Kubebuilder scaffolds an idiomatic Go project with CRD generation, RBAC manifests, and envtest so you can focus on reconciler logic.
§01

What it is

Kubebuilder is the official SIG-API-Machinery SDK for authoring Kubernetes operators in Go. It wraps controller-runtime, controller-gen, and the Kubernetes client libraries into an opinionated project layout. Instead of writing boilerplate for client-gen, informers, and RBAC wiring, you define your API types and let Kubebuilder generate the rest.

It is aimed at platform engineers and SREs who need to extend Kubernetes with custom resources -- database provisioners, certificate managers, or any domain-specific controller.

§02

How it saves time or tokens

Writing a Kubernetes operator from scratch involves hundreds of lines of scaffolding: Makefile, Dockerfile, kustomize configs, deepcopy methods, RBAC manifests, and webhook boilerplate. Kubebuilder generates all of this with two commands. The built-in envtest framework lets you run controllers against a real API server locally without deploying to a cluster, shortening the development cycle from minutes to seconds.

§03

How to use

  1. Install Kubebuilder and bootstrap a new project.
curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/$(go env GOOS)/$(go env GOARCH)
chmod +x kubebuilder && sudo mv kubebuilder /usr/local/bin/

mkdir guestbook && cd guestbook
kubebuilder init --domain example.com --repo example.com/guestbook
  1. Create an API with a new Kind and generate the controller skeleton.
kubebuilder create api --group webapp --version v1 --kind Guestbook
  1. Generate manifests and run the controller locally.
make manifests generate
make install run
§04

Example

A minimal reconciler that logs every event:

func (r *GuestbookReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
    log := log.FromContext(ctx)
    var guestbook webappv1.Guestbook
    if err := r.Get(ctx, req.NamespacedName, &guestbook); err != nil {
        return ctrl.Result{}, client.IgnoreNotFound(err)
    }
    log.Info('reconciling', 'name', guestbook.Name)
    return ctrl.Result{}, nil
}
§05

Related on TokRepo

  • DevOps tools -- More tools for Kubernetes and infrastructure automation.
  • Automation tools -- Workflows that reduce manual operations in cloud-native stacks.
§06

Common pitfalls

  • Forgetting to run make manifests after changing API types causes CRD drift. Always regenerate before deploying.
  • The envtest binary must match your Kubernetes version. Pin it in the Makefile to avoid test failures on CI.
  • Reconcilers should be idempotent. Avoid side effects that break when the controller re-enters the same reconcile loop after a transient error.

Frequently Asked Questions

What is the difference between Kubebuilder and Operator SDK?+

Operator SDK from Red Hat wraps Kubebuilder and adds Helm-based and Ansible-based operator support on top. If you are writing operators in Go, both tools produce nearly identical scaffolding. Kubebuilder is the upstream project; Operator SDK is a superset.

Does Kubebuilder support webhooks?+

Yes. Running `kubebuilder create webhook` scaffolds admission and conversion webhooks. It generates the webhook server, certificate injection, and kustomize patches needed for deployment.

Can I use Kubebuilder with languages other than Go?+

Kubebuilder is Go-only. For other languages, consider kopf (Python), java-operator-sdk (Java), or kube-rs (Rust). These projects serve the same purpose but do not share Kubebuilder's scaffolding.

How do I test a Kubebuilder operator locally?+

Kubebuilder includes envtest, which spins up a lightweight API server and etcd in-process. Run `make test` to execute controller tests against this local API server without needing a full Kubernetes cluster.

What Kubernetes versions does Kubebuilder support?+

Kubebuilder tracks the latest stable Kubernetes releases. Each Kubebuilder release documents its supported Kubernetes version range. Check the compatibility matrix in the project documentation before upgrading.

Citations (3)

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets