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.
Installation avec revue préalable
Cet actif nécessite une revue. Le prompt copié demande un dry-run, affiche les écritures, puis continue seulement après confirmation.
npx -y tokrepo@latest install 95910ea9-38e6-11f1-9bc6-00163e2b0d79 --target codexDry-run d'abord, confirmez les écritures, puis lancez cette commande.
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.
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.
How to use
- 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
- Create an API with a new Kind and generate the controller skeleton.
kubebuilder create api --group webapp --version v1 --kind Guestbook
- Generate manifests and run the controller locally.
make manifests generate
make install run
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
}
Related on TokRepo
- DevOps tools -- More tools for Kubernetes and infrastructure automation.
- Automation tools -- Workflows that reduce manual operations in cloud-native stacks.
Common pitfalls
- Forgetting to run
make manifestsafter 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.
Questions fréquentes
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.
Yes. Running `kubebuilder create webhook` scaffolds admission and conversion webhooks. It generates the webhook server, certificate injection, and kustomize patches needed for deployment.
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.
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.
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.
Sources citées (3)
- Kubebuilder GitHub— Kubebuilder is the official SIG-API-Machinery SDK for Kubernetes operators
- Kubebuilder Book— Wraps controller-runtime and controller-gen for Go-based operators
- Kubernetes CRD Docs— Custom Resource Definitions extend the Kubernetes API
En lien sur TokRepo
Fil de discussion
Actifs similaires
Operator SDK — Build Kubernetes Operators the Easy Way
The Operator SDK provides scaffolding, code generation, and lifecycle management tools for building Kubernetes operators in Go, Ansible, or Helm with best-practice patterns built in.
Refine — React Framework for Building Internal Tools
Refine is an open-source React framework for building admin panels, dashboards, and internal tools. It provides data hooks, auth, access control, routing, and notifications — with full code ownership and no vendor lock-in, unlike visual builders.
Builder.io — Visual Development SDK for React, Vue and More
An open-source visual development SDK that enables drag-and-drop page building using your own React, Vue, Svelte, or Qwik components, with output as clean code or publishable content.
React — The Library for Building User Interfaces
React is the most popular JavaScript library for building user interfaces. Created by Meta, it uses a component-based architecture with a virtual DOM, enabling developers to build fast, interactive web and native applications with declarative, reusable code.