# Kubernetes Operators ## Topics * [KinD](https://kind.sigs.k8s.io/) * [lens](https://k8slens.dev/) Kubernetes IDE * Review API Server and etcd3 * [Operator SDK](https://sdk.operatorframework.io/docs/building-operators/golang/tutorial/) and [Kubebuilder](https://github.com/kubernetes-sigs/kubebuilder) * Example: [memcached-operator](https://github.com/mchirico/memcached-operator) ## KinD Kubernetes in Docker, KinD allows you to quickly build kubernetes clusters in docker. You can also build from source. ```bash= go get sigs.k8s.io/kind # Will need to be in path git clone https://github.com/kubernetes/kubernetes.git cd kubernetes git tag|grep v1.20.5 # v1.20.5 # v1.20.5-rc.0 git checkout v1.20.5 kind build node-image --image=v1.20.5 --kube-root=~/playground/kubernetes # Create image kind create cluster --name v1.20.5 --image=v1.20.5 # Or, more complex kind create cluster --name v1.20.5 --image=v1.20.5 --config configs/kind_basic.yaml # To delete the cluster kind delete --name v1.20.5 cluster # Example of loading images into KinD kind --name v1.20.5 load docker-image memcached-operator:v0.0.1 ``` Here's a link to [configs/kind_basic.yaml](https://github.com/mchirico/k8s/blob/main/configs/kind_basic.yaml) ## Kubebuilder Yes, you'll want to install both. ```bash= os=$(go env GOOS) arch=$(go env GOARCH) # download kubebuilder and extract it to tmp curl -L https://go.kubebuilder.io/dl/2.3.1/${os}/${arch} | tar -xz -C /tmp/ # move to a long-term location and put it on your path # (you'll need to set the KUBEBUILDER_ASSETS env var if you put it somewhere else) sudo mv /tmp/kubebuilder_2.3.1_${os}_${arch} /usr/local/kubebuilder export PATH=$PATH:/usr/local/kubebuilder/bin ``` This will give you the following: ```bash= ls /usr/local/kubebuilder/bin/ etcd kube-apiserver kubebuilder kubectl ``` ## Reconcile Loop ![image](https://user-images.githubusercontent.com/755710/114233660-aed93700-994b-11eb-932a-9d7354af7daf.png) ![image](https://user-images.githubusercontent.com/755710/114233905-05df0c00-994c-11eb-9b4e-1f1959e12949.png) ![image](https://user-images.githubusercontent.com/755710/114234052-3a52c800-994c-11eb-9260-3ed55bc91cf5.png) Reference: ![image](https://user-images.githubusercontent.com/755710/114234157-62422b80-994c-11eb-8d8b-ce97b1433472.png) ## memcached-operator