# README
memcached-operator
My adaptation of the Go Operator Tutorial from the official Operator SDK website
Prerequisites
- Access to a Kubernetes cluster with cert-manager installed
- Go 1.21
- Operator SDK 1.34
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
from3
to5
- Decrease
.spec.size
from5
to1
- Increase
.spec.size
from1
to6
- Decrease
.spec.size
from6
to0
- Decrease
.spec.size
from1
to-1
- Edit
.spec.containerPort
from11211
to0
- Edit
.spec.containerPort
from11211
to33221
To clean up the resources:
kubectl delete -f config/samples/cache_v1alpha1_memcached.yaml
make undeploy