Quickstart for Helm-based Operators
A simple set of instructions to set up and run a Helm-based operator.
This guide walks through an example of building a simple nginx-operator powered by Helm using tools and libraries provided by the Operator SDK.
Prerequisites
- Go through the installation guide.
- User authorized with
cluster-admin
permissions. - An accessible image registry for various operator images (ex. hub.docker.com,
quay.io) and be logged in in your command line environment.
example.com
is used as the registry Docker Hub namespace in these examples. Replace it with another value if using a different registry or namespace.- Authentication and certificates if the registry is private or uses a custom CA.
Steps
- Create a project directory for your project and initialize the project:
mkdir nginx-operator
cd nginx-operator
operator-sdk init --domain example.com --plugins helm
- Create a simple nginx API using Helm’s built-in chart boilerplate (from
helm create
):
operator-sdk create api --group demo --version v1alpha1 --kind Nginx
- Build and push your operator’s image:
make docker-build docker-push IMG="example.com/nginx-operator:v0.0.1"
OLM deployment
- Install OLM:
operator-sdk olm install
- Bundle your operator, then build and push the bundle image (defaults to
example.com/nginx-operator-bundle:v0.0.1
):
make bundle IMG="example.com/nginx-operator:v0.0.1"
make bundle-build bundle-push IMG="example.com/nginx-operator:v0.0.1"
- Run your bundle. If your bundle image is hosted in a registry that is private and/or has a custom CA, these configuration steps must be complete.
operator-sdk run bundle example.com/nginx-operator-bundle:v0.0.1
- Create a sample Nginx custom resource:
$ kubectl apply -f config/samples/demo_v1alpha1_nginx.yaml
nginx.demo.example.com/nginx-sample created
- Uninstall the operator:
operator-sdk cleanup nginx-operator
Direct deployment
- Deploy your operator:
make deploy IMG="example.com/nginx-operator:v0.0.1"
- Create a sample Nginx custom resource:
$ kubectl apply -f config/samples/demo_v1alpha1_nginx.yaml
nginx.demo.example.com/nginx-sample created
- Uninstall the operator:
make undeploy
Next Steps
Read the full tutorial for an in-depth walkthough of building a Helm operator.
Last modified June 8, 2022: fix IMG relvar in helm olm tutorial (#5836) (07b7a7fc)