You’ll need a Kubernetes cluster to run against. You can use KIND to get a local cluster for testing, or run against a remote cluster.
Note: Your controller will automatically use the current context in your kubeconfig file (i.e. whatever cluster kubectl cluster-info
shows).
Prerecuisites for running this lab are:
- A default cluster that you can deploy resources to.
kubectl cluster-info
should show you your current context - Docker installed.
docker version
should return the version - Make installed.
make --version
should return the version - golang v1.24.
go version
should return the version - A Docker registry that you can push images to. You can create a free registry on dockerhub
The operator functionality runs as a container inside the cluster.
Build and push your image to the location specified by IMG
:
make docker-build IMG=<some-registry>/cake-operator:tag
make docker-push IMG=<some-registry>/cake-operator:tag
Create your manifests
make manifests
ls -la config/crd/bases/
will show you the timestamp of the newly created manifest
Deploy the operator to the cluster with the image specified by IMG
:
make deploy IMG=<some-registry>/cake-operator:tag
make install
Notice that lots of Kubernetes Resources have been created as part of the operator.
You should be able to confirm the CRD is installed by
kubectl api-resources -n cake-operator-system
where your 'Cakes' resource type now shows up.
Now it's time to create your cake object using your operator and CRD created in the previous steps:
kubectl apply -f config/samples/tutorials_v1_cake.yaml
Your cake is now up and running! kubectl describe cake cake-sample
confirms some details about your cake such as that it is running on nodeport 30300. Please note if you're running in a local cluster the 'node' may not be your local machine and so in order to view your cake in the browser please forward it to your localhost. Here is a neat guide on how to do it on Rancher Desktop in 10 seconds.
Go to your browser and view your cake; localhost:30300 (or whichever port you assigned on your node)
Change your cake object config/samples/tutorials_v1_cake.yaml
by adding some custom configuration, such as a colour and a decoration, then delete and apply the object again.
kubectl delete -f config/samples/tutorials_v1_cake.yaml
kubectl apply -f config/samples/tutorials_v1_cake.yaml
To delete the CRDs from the cluster:
make uninstall
UnDeploy the controller to the cluster:
make undeploy
// TODO(user): Add detailed information on how you would like others to contribute to this project
This project aims to follow the Kubernetes Operator pattern
It uses Controllers which provides a reconcile function responsible for synchronizing resources untile the desired state is reached on the cluster
If you are editing the API definitions, don't forget to generate the manifests such as CRs or CRDs using:
make manifests
NOTE: Run make --help
for more information on all potential make
targets
More information can be found via the Kubebuilder Documentation
This operator was built using this guide
Copyright 2022.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.