memcached-operator
My adaptation of the Go Operator Tutorial from the official Operator SDK website
Prerequisites
If you do not already have a Kubernetes cluster, get started with Kubernetes in no time with kind.
An example of installing cert-manager on a fresh kind cluster using the official Helm chart:
helm repo add jetstack https://charts.jetstack.io
helm repo update
helm -n cert-manager install \
cert-manager \
jetstack/cert-manager \
--version v1.14.4 \
--set installCRDs=true \
--create-namespace
Developing
Fork and clone this repository, make it your working directory, then run:
make deploy
This runs the Memcached operator as a Kubernetes Deployment under the namespace memcached-operator-system:
kubectl -n memcached-operator-system get deploy
Sample output:
NAME READY UP-TO-DATE AVAILABLE AGE
memcached-operator-controller-manager 1/1 1 1 8m
Now deploy a sample Memcached custom resource (CR) using the template available under config/samples/cache_v1alpha1_memcached.yaml:
kubectl apply -f config/samples/cache_v1alpha1_memcached.yaml
Observe that the Memcached CR is created along with its associated Deployment and Pods:
kubectl get memcached,deploy,pod
Sample output:
NAME AGE
memcached.cache.donaldsebleung.com/memcached-sample 37s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/memcached-sample 3/3 3 3 22s
NAME READY STATUS RESTARTS AGE
pod/memcached-sample-df947c465-85rh4 1/1 Running 0 22s
pod/memcached-sample-df947c465-ck4ht 1/1 Running 0 22s
pod/memcached-sample-df947c465-jvzcf 1/1 Running 0 22s
Now edit the Memcached CR with kubectl edit and observe which modifications are allowed / rejected:
- Increase
.spec.size from 3 to 5
- Decrease
.spec.size from 5 to 1
- Increase
.spec.size from 1 to 6
- Decrease
.spec.size from 6 to 0
- Decrease
.spec.size from 1 to -1
- Edit
.spec.containerPort from 11211 to 0
- Edit
.spec.containerPort from 11211 to 33221
To clean up the resources:
kubectl delete -f config/samples/cache_v1alpha1_memcached.yaml
make undeploy
See also
- Go Operator Tutorial | Operator SDK
- Admission Webhooks | Operator SDK
License
Apache 2.0