- A buildable Go module
- A working
Makefile - The controller-runtime manager entry point
Prerequisites
- Go installed and available on your
PATH. Ifgo versionfails, install Go from the official Go installation page: https://go.dev/doc/install
Install Kubebuilder
Kubebuilder is not installed by default. Follow the Kubebuilder quick-start installation instructions:- Official docs: https://book.kubebuilder.io/quick-start.html
Make sure
kubebuilder is executable and located in a directory that is on your PATH (for example /usr/local/bin).Kubebuilder will not scaffold into a directory that already contains files. Always run
kubebuilder init from an empty project folder (check your editor or run ls -la first). If the folder contains files, create a clean directory before continuing.Verify toolchain
Confirm both Kubebuilder and Go are installed and reporting compatible versions. If versions differ significantly, the project layout and generated imports may vary.Initialize the project
kubebuilder init scaffolds a new operator project. The most important flags:
Pick these values carefully:
domain and repo are embedded into package import paths and generated manifests.
Example init command:
What Kubebuilder creates
Afterkubebuilder init completes, you’ll see a small project layout with source, build, and configuration files. Key files and directories:
A sample
PROJECT file:
Build the scaffold
The scaffold is intended to compile immediately. Ifmake build succeeds, your Go toolchain and module path are configured correctly.
Scaffold and build:
Next steps
Now that the skeleton is in place and the manager compiles, continue with:- A tour of the directories and files Kubebuilder
initcreated (cmd/,config/,api/,controllers/) - Using
kubebuilder create apito define your first CustomResource and controller - Implementing reconcile logic in the generated controller
- Kubebuilder Quick Start: https://book.kubebuilder.io/quick-start.html
- Kubernetes documentation: https://kubernetes.io/docs/
- Go installation: https://go.dev/doc/install