This is an example without any real functionality, simply for showcasing a pattern.
This Helm chart allows you to deploy a Custom Resource Definition (CRD) and an Operator to a Kubernetes cluster. The Operator's job is to create a pod whenever an instance of the custom resource is created, as well as to delete the pod when the corresponding instance is deleted.
Before you begin, make sure you have the following:
- Kubernetes cluster up and running
- Helm installed and configured to work with your cluster
Follow these steps to deploy the CRD and Operator using the Helm chart:
-
Build Docker image: Navigate to the operator directory and build the Docker image for the Operator using the provided Dockerfile. Make sure you have Docker installed and running. You can use the following command:
cd operator docker build -t your-image-tag .
Replace
your-image-tagwith the desired tag for your Docker image. Push it to your repository of choice, or keep it local for testing. -
Set the image in values.yaml: Open the
values.yamlfile in the root directory of this Helm chart. Find theimagefield and update it with the correct Docker image details. For example:image: your-docker-repo/your-image:your-image-tag
Replace
your-docker-repo/your-imagewith the repository (if not locally testing) and image name where you pushed your Docker image, andyour-image-tagwith the specific tag you used. -
Install the Helm chart: Run the following command to install the chart in your Kubernetes cluster:
helm install your-release-name .Replace
your-release-namewith the desired name for your Helm release. -
Apply the custom resource instances: Create instances of the custom resource (cats) by applying the provided YAML files located in the
example-catsfolder within the repository. For example:kubectl apply -f example-cats/sprinkles.yaml
This will create instances of the custom resource, and the Operator should create corresponding pods for each instance.
-
Verify pod creation: Use the following command to check if the pods have been created:
kubectl get pods
You should see pods with names corresponding to the created cat instances.
-
Delete a custom resource instance: Delete one of the custom resource instances using the following command:
kubectl delete -f example-cats/sprinkles.yaml
The Operator should detect the deletion and delete the corresponding pod.
-
Verify pod deletion: Use the following command to check if the pod has been deleted:
kubectl get pods
The pod associated with the deleted cat instance should no longer be present.
To uninstall the Helm chart and remove all the deployed resources, run the following command:
helm uninstall your-release-nameReplace your-release-name with the name of your Helm release.