Jump Start Using the Operator-SDK

Welcome

If you are considering making a Kubernetes Operator, you’re not alone. Since their launch in 2016, Kubernetes Operators have been solving notoriously tricky problems for Kubernetes users. Operators reduce the complexity of deploying a stateful or distributed cluster application on Kubernetes. They help users to achieve the simplicity of initial application deployment with Helm charts but without the security implications of running Tiller or saving the state of a deployment. Or they also help those starting to develop against the Kubernetes API. If you’re looking to build an Operator for any of the above reasons, you’ve come to the right place!

What exactly is an Operator?

If you would like to get familiar with the Operator pattern, please read on here.

How do I start writing an Operator?

Normally, without any tools and just the basic libraries you would need to learn all about the Kubernetes API, the client-go library and the controller-runtime to even be able to start watching for certain events or objects in Kubernetes.

Fortunately there is the operator-sdk, part of the Operator Framework, a community project that aims at simplifying the whole process of Operator creation to just writing the custom operational logic inside the control loop.

There are basically three ways of getting there, resulting in the three types of Operators the SDK supports:

Operator TypeWhat the SDK generatesWhat you need to define
Go Operator
  • General go program structure
  • Boilerplate code to talk to the Kubernetes API
  • Boilerplate code to watch for Kubernetes objects of interest
  • An entry point to the reconciliation loop
  • An example YAML files based on CRDs
  • Custom objects via CRDs
  • Control loop logic in Go
  • Potentially artistic stunts only possible by talking directly to the API from Go
Ansible Operator
  • A Go program that runs an Ansible playbook or role every time a certain type of object is detected / modified
  • Ansible playbook or role
  • Custom objects via CRD
Helm Operator
  • A custom object via CRD containing the same properties as the chart's values.yaml
  • A Go program that reads a helm chart and deploys all its resources
  • Watch statements to detect changes in the custom objects specification, re-deploying all resources with updated values
  • The location / repository of the helm chart

This results in different maturity models of Operators:

Interested? Try the operator-sdk today by following this Getting Started Guide.

Already have an Operator? Discover how to contribute it to OperatorHub.io here.