Kubebuilder
Kubebuilder
Kubernetes API development framework
Kubebuilder is the framework used to build the Control Plane's operators and custom resources.
Development framework
Kubebuilder provides the scaffolding and tooling used to develop the Control Plane's operators and custom resources.
Overviewโ
Kubebuilder is a framework for building Kubernetes APIs using CRDs, controllers, and webhooks. It's designed to simplify the development of Kubernetes operators and custom resources by providing code generation, scaffolding, and testing capabilities.

Why Kubebuilder?โ
๐๏ธ Standardized Structure
Provides a consistent project structure that follows Kubernetes community best practices.
โก Rapid Development
Accelerates development with automatic generation of boilerplate code and manifests.
๐งฉ Controller Runtime
Built on the battle-tested controller-runtime library used by Kubernetes core components.
๐ Security by Default
Automatically generates RBAC rules based on controller access patterns.
๐งช Testing Framework
Includes a testing framework that simulates the Kubernetes API server for unit and integration tests.
๐ Production-Ready
Used by major Kubernetes projects and enterprises for building production operators.
๐๏ธ Scaffolding
Generate code and manifests for new API types and controllers.
๐งช Testing
Framework for controller and webhook testing with envtest.
๐ RBAC
Automatic generation of role-based access control manifests.
๐ Webhooks
Infrastructure for validation and defaulting webhooks.
๐ Documentation
Marker-based API documentation generation.
๐ง CLI Tools
Command-line tools for project management and scaffolding.
Project Structureโ
The Control Plane follows the standard Kubebuilder project structure:
โโโ api/
โ โโโ v1/
โ โโโ rover_types.go
โ โโโ apispecification_types.go
โ โโโ groupversion_info.go
โ โโโ zz_generated.deepcopy.go
โโโ controllers/
โ โโโ rover_controller.go
โ โโโ apispecification_controller.go
โ โโโ suite_test.go
โโโ config/
โ โโโ crd/
โ โ โโโ bases/
โ โ โโโ rover.cp.ei.telekom.de_rovers.yaml
โ โโโ rbac/
โ โ โโโ role.yaml
โ โ โโโ role_binding.yaml
โ โโโ manager/
โ โ โโโ manager.yaml
โ โโโ samples/
โ โโโ rover_v1_rover.yaml
โโโ main.go
Standardized organization
The Kubebuilder project structure ensures consistency across all Control Plane operators, making it easier to navigate, understand, and maintain the codebase.
Working with Kubebuilderโ
Creating a New APIโ
The Control Plane uses Kubebuilder to scaffold new APIs and controllers:
# Create a new API with group 'gateway', version 'v1', kind 'Route'
kubebuilder create api --group gateway --version v1 --kind Route
# Create a new webhook for an existing API
kubebuilder create webhook --group gateway --version v1 --kind Route --defaulting --programmatic-validation
Generating CRDsโ
Kubebuilder automatically generates CRDs from Go types with markers:
# Generate CRDs from API definitions
make manifests
# Install CRDs into a cluster
make install
Running Controllers Locallyโ
The Control Plane developers can run controllers locally for testing:
# Run controller against a remote cluster
make run
# Run controller with specific configuration
KUBECONFIG=/path/to/kubeconfig ENABLE_WEBHOOKS=false make run
Testing with Kubebuilderโ
Kubebuilder Testing
Kubebuilder provides the envtest package, which sets up a temporary API server for testing controllers without requiring a real Kubernetes cluster.
Best Practicesโ
Control Plane patterns
The Control Plane follows these best practices for Kubebuilder-based development.
API Design
- Follow Kubernetes API conventions
- Use CRD validation for all fields
- Separate spec (desired state) from status (observed state)
- Define clear ownership and dependency relationships
Controller Implementation
- Make reconciliation idempotent
- Use finalizers for cleanup operations
- Log relevant information at appropriate levels
- Handle errors with appropriate retry strategies
Resource Management
- Implement owner references for garbage collection
- Set resource requests and limits appropriately
- Use metrics for performance monitoring
- Implement proper error handling and reporting
Testing
- Write comprehensive unit tests
- Use envtest for controller integration testing
- Test failure scenarios and edge cases
- Verify webhooks with admission review requests
Related Resourcesโ
Kubernetes
Learn about the core platform extended by Kubebuilder.
Controller Runtime
Explore the library that powers Kubebuilder-based controllers.