Quickstart for Ansible-based Operators

A simple set of instructions to set up and run an Ansible-based operator.

This guide walks through an example of building a simple memcached-operator powered by Ansible using tools and libraries provided by the Operator SDK.

Prerequisites

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 --plugins ansible
  1. Create a simple Memcached API:
  1. operator-sdk create api --group cache --version v1alpha1 --kind Memcached --generate-role
  1. Use the built-in Makefile targets to build and push your operator. Make sure to define IMG when you call make:
  1. export OPERATOR_IMG="quay.io/example/memcached-operator:v0.0.1"
  2. make docker-build docker-push IMG=$OPERATOR_IMG

OLM deployment

  1. Install OLM:
  1. operator-sdk olm install
  1. Bundle your operator and push the bundle image:
  1. make bundle IMG=$OPERATOR_IMG
  2. # Note the "-bundle" component in the image name below.
  3. export BUNDLE_IMG="quay.io/example/memcached-operator-bundle:v0.0.1"
  4. make bundle-build BUNDLE_IMG=$BUNDLE_IMG
  5. make docker-push IMG=$BUNDLE_IMG
  1. Run your bundle:
  1. operator-sdk run bundle $BUNDLE_IMG
  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=$OPERATOR_IMG
  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 Ansible operator.

Last modified January 20, 2021: Updates to the tutorial docs (#4395) (160cd9f6)