Quickstart for Go-based Operators

A simple set of instructions to set up and run a Go-based operator.

This guide walks through an example of building a simple memcached-operator 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

  1. Create a project directory for your project and initialize the project:
  1. mkdir memcached-operator
  2. cd memcached-operator
  3. operator-sdk init --domain example.com --repo github.com/example/memcached-operator
  1. Create a simple Memcached API:
  1. operator-sdk create api --group cache --version v1alpha1 --kind Memcached --resource --controller
  1. Build and push your operator’s image:
  1. make docker-build docker-push IMG="example.com/memcached-operator:v0.0.1"

OLM deployment

  1. Install OLM:
  1. operator-sdk olm install
  1. Bundle your operator, then build and push the bundle image (defaults to example.com/memcached-operator-bundle:v0.0.1):
  1. make bundle IMG="example.com/memcached-operator:v0.0.1"
  2. make bundle-build bundle-push BUNDLE_IMG="example.com/memcached-operator-bundle:v0.0.1"
  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.
  1. operator-sdk run bundle <some-registry>/memcached-operator-bundle:v0.0.1
  1. Create a sample Memcached custom resource:
  1. $ kubectl apply -f config/samples/cache_v1alpha1_memcached.yaml
  2. memcached.cache.example.com/memcached-sample created
  1. Uninstall the operator:
  1. operator-sdk cleanup memcached-operator

Direct deployment

  1. Deploy your operator:
  1. make deploy IMG="example.com/memcached-operator:v0.0.1"
  1. Create a sample Memcached custom resource:
  1. $ kubectl apply -f config/samples/cache_v1alpha1_memcached.yaml
  2. memcached.cache.example.com/memcached-sample created
  1. Uninstall the operator:
  1. make undeploy

Next Steps

Read the full tutorial for an in-depth walkthough of building a Go operator.

Last modified October 4, 2021: fixes #5237 (#5238) (acbe1bc7)