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://github.com/operator-framework/operator-sdk/blob/master/doc/helm/user-guide.md
- Operator-Framework: https://github.com/operator-framework
- Operator-SDK: https://github.com/operator-framework/operator-sdk/
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 in our $GOPATH/src/
directory:
mkdir -p $GOPATH/src/github.com/redhat/
Navigate to the directory:
cd $GOPATH/src/github.com/redhat/
Create a new Helm-based Operator SDK project for the CockroachDB Operator:
operator-sdk new cockroachdb-operator --type=helm --helm-chart cockroachdb --helm-chart-repo https://kubernetes-charts.storage.googleapis.com --helm-chart-version 3.0.7
Navigate to the top-level project directory:
cd cockroachdb-operator
Project Scaffolding Layout
After creating a new operator project using operator-sdk new --type helm
, the project directory has numerous generated folders and files. The following table describes a basic rundown of the generated files and directories:
File/Folders | Purpose |
---|---|
deploy | Contains a generic set of Kubernetes manifests for deploying this operator on a Kubernetes cluster. |
helm-charts/ |
Contains a Helm chart initialized using the equivalent of [helm create ][docs_helm_create] |
build | Contains scripts that the operator-sdk uses for build and initialization. |
watches.yaml | Contains Group, Version, Kind, and Helm chart location. |