In the previous learning modules, we covered how to easily create the following types of Operators with the Operator SDK:
Go: Ideal for traditional software development teams that want to get to a fully auto-pilot Operator. It gives you the ability to leverage the same Kubernetes libraries the upstream projects uses under the hood. Check out the Go Getting Started guide.
Ansible: Useful for infrastructure-focused teams that have investment in Ansible modules but want to use them in a Kubernetes-native way. Also great for using Ansible to configure off-cluster objects like hardware load balancers. Check out the Ansible Getting Started guide.
We will now focus on the easiest way to get started developing an Operator:
- Helm: Useful for securely running Helm charts without Tiller and it doesn’t rely on manual invocation of Helm to reconfigure your apps. Check out the Helm Operator Getting Started guide for more information.
Creating a CockroachDB Operator from a Helm Chart
In this tutorial, we will create a CockroachDB Operator from an existing CockroachDB Helm Chart.
CockroachDB is a distributed SQL database built on a transactional and strongly-consistent key-value store. It can:
- Scale horizontally.
- Survive disk, machine, rack, and even datacenter failures with minimal latency disruption and no manual intervention.
- Supports strongly-consistent ACID transactions and provides a familiar SQL API for structuring, manipulating, and querying data.
Let's begin!
Thank you for taking a closer look at Operator SDK's Helm Operator. For more information, check out the links below:
GitHub
- Helm Operator Getting Started guide: https://sdk.operatorframework.io/docs/building-operators/helm/
- Operator-Framework: https://github.com/operator-framework
- Operator-SDK: https://sdk.operatorframework.io
Chat
- Kubernetes Slack Chat (upstream): #kubernetes-operators at https://kubernetes.slack.com/
- Operator-Framework on Google Groups: https://groups.google.com/forum/#!forum/operator-framework
- OpenShift Operators Special Interest Group (SIG): https://commons.openshift.org/sig/OpenshiftOperators.html

Steps
Operator SDK with Helm
Initialize the Project
Let's begin my creating a new project called myproject
:
oc new-project myproject
CockroachDB is a database so let's ensure we have accessible persistent storage by adding some current PersistentVolumes
to a StorageClass
called local-storage
:
for num in {02..06}; do oc patch pv pv00$num --type='json' -p '[{"op": "replace", "path": "/spec/storageClassName", "value":local-storage}]'; done;
Let's now create a new directory for our project:
mkdir -p $HOME/projects/cockroachdb-operator
Navigate to the directory:
cd $HOME/projects/cockroachdb-operator
Create a new Helm-based Operator SDK project for the CockroachDB Operator:
operator-sdk init --plugins=helm --domain example.com
Automatically fetch the Cockroachdb Helm Chart and generate the CRD/API:
operator-sdk create api --helm-chart=cockroachdb --helm-chart-repo=https://kubernetes-charts.storage.googleapis.com --helm-chart-version=3.0.7
Project Scaffolding Layout
After creating a new operator project the directory has numerous generated folders and files. The following table describes a basic rundown of each generated file/directory.
File/Folders | Purpose |
---|---|
config | Kustomize YAML definitions required to launch our controller on a cluster. It is the target directory to hold our CustomResourceDefinitions, RBAC configuration, and WebhookConfigurations. |
Dockerfile | The container build file used to build your Ansible Operator container image. |
helm-charts | The location for the specified helm-charts. |
Makefile | Make targets for building and deploying your controller. |
PROJECT | Kubebuilder metadata for scaffolding new components. |
watches.yaml | Contains Group, Version, Kind, and desired chart. |