Initialize and Create an API

Create a new namespace called myproject, and set kubectl's default namespace to it:

kubectl create namespace myproject
kubectl config set-context --current --namespace=myproject

Create a new directory for the project and cd into it:

mkdir -p memcached-operator
cd memcached-operator

Initialize a new Go-based Operator SDK project for the Memcached Operator:

operator-sdk init --domain example.com --repo github.com/example/memcached-operator

Add a new Custom Resource Definition (CRD) called Memcached with APIVersion cache.example.com/v1alpha1 and Kind Memcached. The CRD is the schema that defines the custom API. The operator-sdk create subcommand will also create the boilerplate controller logic and Kustomize configuration files.

operator-sdk create api --group cache --version v1alpha1 --kind Memcached --resource --controller

You should now see the api/, config/, and controllers/ directories in your project directory when you run ls.

NOTE: This lesson covers the default case of a single group API. If you need to support Multi-Group APIs see the Single Group to Multi-Group doc.