To quote the Kubernetes website, “The Operator pattern captures how you can write code to automate a task beyond what Kubernetes itself provides.” The following is an compendium to use while Learning Operators.
The defacto SDK to use is the Operator SDK which provides HELM, Ansible and GO scaffolding to support your implementation of the Operator pattern.
The following are education classes on the OperatorSDK
- IBM: CO0201EN Kubernetes Operators Intermediate – introduces core operator concepts and reconciliation with Ansible, Helm and Golang
- IBM: CO0302EN Kubernetes Operators Advanced – covers golang-based operator reconciliation, OLM and Scorecard testing
When Running through the CO0201EN intermediate operators course, I did hit the case where I had to create a ClusterRole and ClusterRoleBinding for the ServiceAccount, here is a snippet that might helper others:
apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: namespace: memcached-operator-system name: service-reader-cr-mc rules: - apiGroups: ["cache.bastide.org"] # "" indicates the core API group resources: ["memcacheds"] verbs: ["get", "list", "watch", "create", "update", "patch", "delete"] --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: namespace: memcached-operator-system name: ext-role-binding roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: service-reader-cr-mc subjects: - kind: ServiceAccount namespace: memcached-operator-system name: memcached-operator-controller-manager
The reason for the above, I missed adding a kubebuilder declaration:
Thanks to https://stackoverflow.com/a/60334649/1873438
The following are articles worth reviewing:
- Kube by Example: Operator Framework – A comprehensive code rich site with lots of examples. Kudos to the Authors.
- IBM Developer: Explanation of Memcached operator code – A flavor of the memcached in the CO0201EN course for IBM Cloud and OpenShift.
- Multi-architecture images with Docker – Particularly important if you are targeting multiple architectures.
- Red Hat: Write Kubernetes in Java with the Java Operator SDK
- Learning Path internal to IBM – Kubernetes Operators
The following are good Go resources:
- Go Code Comments – To write idiomatic Go, you should review the Code Review comments.
- Getting to Go: The Journey of Go’s Garbage Collector – The reference for Go and Garbage Collection in go
- An overview of memory management in Go – good overview of Go Memory Management
- Golang: Cost of using the heap – net 1M allocation seems to stay in the stack, outside it seems to be on the heap
golangci-lint– The aggregated linters project is worthy of an installation and use. It’ll catch many issues and has a corresponding GitHub Action.
- Go in 3 Weeks A comprehensive training for Go. Companion to GitHub Repo
- Defensive Coding Guide: The Go Programming Language
The following are good OpenShift resources:
- Create OpenShift Plugins – You must have a CLI plug-in file that begins with
kubectl-. You create a file and put it in /usr/local/bin/
- Details on running Code Ready Containers on Linux – The key hack I learned awas to ssh -i ~/.crc/machines/crc/id_ecdsa core@<any host in the /etc/hosts>
- I ran on VirtualBox Ubuntu 20.04 with Guest Additions Installed
- Virtual Box Settings for the Machine – 6 CPU, 18G
- System > Processor > Enable PAE/NX and Enable Nested VT-X/AMD-V (which is a must for it to work)
- Network > Change Adapter Type to virtio-net and Set Promiscuous Mode to Allow VMS
- Install openssh-server so you can login remotely
- It will not install without a windowing system, so I have the default windowing environment installed.
- Note, I still get a failure on startup complaining about a timeout. I waited about 15 minutes post this, and the command oc get nodes –context admin –cluster crc –kubeconfig .crc/cache/crc_libvirt_4.10.3_amd64/kubeconfig now works.
- CRC virsh cheatsheet – If you are running Code Ready Containers and need to debug, you can use the virsh cheatsheet.