based on https://betterprogramming.pub/build-a-kubernetes-operator-in-10-minutes-11eec1492d30
Note: this repo is part of webofmars labs project. You can check other labs here https://github.com/webofmars/labs.
- go version v1.17.9+
- docker version 17.03+
- kubectl version v1.11.3+
- access to a Kubernetes v1.11.3+ cluster (I highly suggest using kind to set up your own local cluster, it’s very easy to use!).
curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/$(go env GOOS)/$(go env GOARCH) && \
chmod +x kubebuilder && mv kubebuilder /usr/local/bin/
or
asdf plugin add kubebuilder
asdf install
kubebuilder init --domain webofmars.com --repo webofmars.com/pizza
kubebuilder create api --group pizza --version v1 --kind Pizza
go mod tidy
make generate
- edit the file
api/v1/pizza_types.go
- edit the file
controllers/pizza_controller.go
and inseert your own logic for a pizza
make manifests
NB: you need a working kubectl connected to your dev cluster in order to test it.
make install
kubectl get crds
Run the controller locally (it can later be packaged through helm or other means and run in a the kubernetes cluster).
make run
- edit file
config/samples/pizza_v1_pizza.yaml
to match a valid pizza spec as defined inpizza_types.go
kubectl apply -f config/samples/pizza_v1_pizza.yaml
after a while you should see the controller reconcile loop pass over the pizza object and modify it if you instructed to do so in the controller (check step 4 code)
make docker-build
make docker-push
You can now add some items to spec and status to reflect a valid pizza from your logic and play with thee controller