- Understand CRs
- Define a CR using CRD
- Understand Custom Controller
- Write a Custom Controller (crd-controller) to manage a Custom Resource (Kluster)
- Group Name:
neajmorshad.dev
- Version Name:
v1beta1
- Resource Name:
Kluster
- go to the project path. Example:
$HOME/go/src/github.com/Neaj-Morshad-101/crd-controller/
- import
"k8s.io/code-generator"
intomain.go
- run
go install sigs.k8s.io/controller-tools/cmd/controller-gen@latest
- run
go mod tidy;go mod vendor
- run
chmod +x ./hack/update-codegen.sh
- run
chmod +x vendor/k8s.io/code-generator/generate-groups.sh
- run
hack/update-codegen.sh
- again run
go mod tidy;go mod vendor
- Run
depelopmentDir=$(pwd)
- Then run:
controller-gen rbac:roleName=controller-perms crd paths=github.com/Neaj-Morshad-101/crd-controller/pkg/apis/neajmorshad.dev/v1beta1 crd:crdVersions=v1 output:crd:dir=$depelopmentDir/manifests output:stdout
kubectl apply -f neajmorshad.dev_klusters.yaml
- Create an example yaml file like
manifests/kluster.yaml
. - Run
kubectl apply -f manifests/kluster.yaml
. - Run
kubectl get kluster
.
https://www.linkedin.com/pulse/kubernetes-custom-controllers-part-1-kritik-sachdeva/ https://www.linkedin.com/pulse/kubernetes-custom-controller-part-2-kritik-sachdeva/ Workqueue example: https://github.com/kubernetes/client-go/tree/master/examples/workqueue Sample-controller https://github.com/kubernetes/sample-controller Code-Generator https://github.com/kubernetes/code-generator