Running the memcached Operator

Once the CRD is registered, there are two ways to run the Operator:

  • As a Pod inside a Kubernetes cluster
  • As a Go program outside the cluster using Operator-SDK. This is great for local development of your Operator.

In this lesson, you will run the Operator as a Go program outside of the cluster using operator-sdk and your credentials inside kubeconfig.

Once running, the command will block the current terminal session. You can continue interacting with the cluster by opening a new terminal window.

Like earlier steps, running the Operator in this local test is driven by a make target, in this case make run.

WATCH_NAMESPACE=myproject make run

In a new terminal, inspect the Custom Resource manifest:

cd memcached-operator
cat config/samples/cache_v1alpha1_memcached.yaml

Ensure your `kind: Memcached` Custom Resource (CR) is updated with `spec.size`

kind: Memcached
  name: memcached-sample
  size: 3

Ensure your kubectl commands in the new terminal target your myproject namespace:

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

Deploy your PodSet Custom Resource to the cluster:

kubectl create -f config/samples/cache_v1alpha1_memcached.yaml

Verify the memcached exists with kubectl get memcached, and check that the operator has created the 3 pods you specified with kubectl get pods.

Verify that status shows the name of the pods currently owned by the Memcached:

kubectl get memcached memcached-sample -o yaml

A custom resource can be addressed and manipulated in the usual ways, like any other Kubernetes resource. For example,  you can increase the number of replicas owned by the memcached custom resource with the standard kubectl patch technique:

kubectl patch memcached memcached-sample --type='json' -p '[{"op": "replace", "path": "/spec/size", "value":5}]'

One more invocation of kubectl get pods should show 5 of them running.