Skip to main content
This lesson recreates the Kubebuilder scaffold used in later labs. Goal: initialize a webapp operator project with the exact course identifiers, generate the CRD manifest, and confirm the manager binary compiles. Many subsequent labs depend on this scaffold, so keeping the domain, repo path, group, version, and kind correct is crucial.
Make sure the domain, repository path, and project name you pass to kubebuilder init match the exact values shown below: domain kodekloud.com, repo github.com/kodekloud/webapp-operator, and project name webapp-operator. These identifiers are referenced across the scaffold and in generated API group names.
Table of contents:
    1. Create the project scaffold
    1. Add the WebApp API
    1. Confirm scaffolded files
    1. Generate CRD manifests
    1. Build the manager (sanity build)
    1. Confirm project metadata
  • Links and references

1) Create the project scaffold

Initialize the Kubebuilder project using the course-specific identifiers. This sets the project-wide domain, repository path, and project name that Kubebuilder uses to build your API group names and module paths.
After the command completes, open PROJECT (project config) and confirm these values remain set. Example configuration created by Kubebuilder:
Why this matters: Kubebuilder uses domain + group to assemble the fully qualified API group (for example, webapp.kodekloud.com). If domain/repo/projectName are incorrect, generated import paths and CRD names will differ from the course expectations.

2) Add the WebApp API

Scaffold the API types and controller for the WebApp resource:
This command generates:
  • API type definitions (Go structs for Spec and Status) in api/v1/webapp_types.go.
  • Group/version registration in api/v1/groupversion_info.go.
  • The reconciler/controller skeleton in controllers/webapp_controller.go.
  • Tests and other scaffolded files (e.g., controllers/webapp_controller_test.go).
Example (trimmed) output:
Notes:
  • The --resource flag creates the CRD-related type and markers.
  • The --controller flag scaffolds a reconciler skeleton to watch and reconcile WebApp resources.

3) Confirm scaffolded files

Open your project in an editor (e.g., VS Code) and confirm these generated files exist and are populated: The generated cmd/main.go will register your API with the manager’s scheme. Example snippet:
This ensures your webappv1 types are registered and available to the manager. When importing standard Kubernetes types later (e.g., apps/v1), the code uses aliases like appsv1 to avoid naming collisions.
If webappv1.AddToScheme(scheme) is missing from cmd/main.go, the manager won’t recognize your custom API and controller setup will fail. Do not remove the scaffolded scheme registration lines.

4) Generate CRD manifests

Generate the CRD YAML using the provided Make target:
What this does:
  • Runs controller-gen to read the marker comments in your Go types.
  • Emits CRD YAML and other resource manifests under config/.
After running, confirm the CRD YAML exists at:
If you edited API types or marker comments and the CRD file is missing or stale, re-run make manifests.

5) Build the manager (sanity build)

Compile the manager binary to ensure the project builds cleanly:
This runs formatting, vetting, and builds cmd/main.go, producing bin/manager. Typical output:
A successful build verifies that:
  • Generated types and controllers compile.
  • The project’s module and imports are correct.
  • The manager binary exists and is ready for further development or testing.

6) Confirm project metadata

Verify project configuration and the resource metadata added by create api. The project config and resource list should reflect the course identifiers and the WebApp resource. Representative excerpt:
Confirm these specific values:
  • domain: kodekloud.com
  • repo: github.com/kodekloud/webapp-operator
  • projectName: webapp-operator
  • resource group: webapp
  • version: v1
  • kind: WebApp
  • controller: true
These settings are the skeleton for implementing the reconciler logic, wiring controller behavior, and testing the operator end-to-end. This scaffold completes the baseline operator structure. Next steps typically implement reconciliation logic in controllers/webapp_controller.go, add RBAC markers, and write e2e tests to validate operator behavior.

Watch Video