# kubebuilder init
kubebuilder init --domain my.domain.com --repo github.com/my-org/my-operator
# define resources
kubebuilder create api --group my-operator --version v1alpha1 --kind MyCustomResource
Create Resource [y/n]
y
Create Controller [y/n]
y
# build the operator
make
Edit types.go to define API objects
# Generate CRD, RBAC, etc by controller-gen (Or it's ok to run make simply)
make manifests
# Run "make" to regenerate code after modifying types.go
make
TIPS
+kubebuilder:validation:Required
- controller-gen analyzes the maker and auto generate CRD, RBAC, etc.
+optional
- Manifest for CRD is auto generated in
make manifest
ormake
- Manifest for CRD is auto generated in
-
Implement Reconcile in controller.go
-
Edit main func in main.go
-
Run the operator
# Regist the CRDs to Kubernetes cluster
make install
# Run Go process in local environment
make run
- Install Instances of Custom Resources
kubectl apply -f config/samples/
- Run it on the cluster
# Build and push your image to the location specified by IMG:
make docker-build docker-push IMG=<some-registry>/<project-name>:tag
# Deploy the controller to the cluster with image specified by IMG:
make deploy IMG=<some-registry>/<project-name>:tag
# undeploy
make undeploy