Demo application containing Kubernetes (K8s) Operator solution in pure Golang.
Entire playbook assumes that you are using Windows 11 OS and PowerShell as CLI and in some stages Linux WSL.
All the steps require Linux WSL with the following version:
wsl --list --verbose
NAME STATE VERSION
* Ubuntu-22.04 Running 2
docker-desktop Running 2
The current Linux WSL distro is:
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.5 LTS
Release: 22.04
Codename: jammy
-
Manually install the prerequisites
-
kubebuildermkdir -p <path/to/codebase/>/bin cd <path/to/codebase/>/bin curl -L -o kubebuilder https://github.com/kubernetes-sigs/kubebuilder/releases/download/v4.9.0/kubebuilder_linux_amd64 chmod +x kubebuilder ./kubebuilder version sudo cp -avx kubebuilder /usr/local/bin/kubebuilder which kubebuilder kubebuilder version -
use standard Linux approach to install
Go,kubectl,kind, anddockerVersions:
# Go SDK go version go version go1.24.5 linux/amd64 # kubectl Client Version: v1.34.1 Kustomize Version: v5.7.1 Server Version: v1.32.0 # kind kind version kind v0.22.0 go1.20.13 linux/amd64 # docker docker version Client: Version: 28.4.0 API version: 1.51 Go version: go1.24.7 Git commit: d8eb465 Built: Wed Sep 3 20:56:28 2025 OS/Arch: linux/amd64 Context: default Server: Docker Desktop 4.47.0 (206054) Engine: Version: 28.4.0 API version: 1.51 (minimum version 1.24) Go version: go1.24.7 Git commit: 249d679 Built: Wed Sep 3 20:57:37 2025 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.7.27 GitCommit: 05044ec0a9a75232cad458027ca83437aae3f4da runc: Version: 1.2.5 GitCommit: v1.2.5-0-g59923ef docker-init: Version: 0.19.0 GitCommit: de40ad0
-
-
Clone the repository
cd <path/to/codebase>/ git clone https://github.com/norbix/demo2_k8soperator_golang.git -
Start
Docker DesktopStart-Process "C:\Program Files\Docker\Docker\Docker Desktop.exe" -WindowStyle Minimized
-
Start
K8s clusterkind create cluster --name demo2-k8soperator-golang && \ sleep 3 && \ kind get clusters && \ sleep 3 && \ kubectl cluster-info && \ sleep 3 && \ kubectl config get-contexts && \ kubectl get ns
-
Scaffoldprojectkubebuilder init --domain norbix.io --repo github.com/norbix/demo2-k8soperator-golang --project-name demo2-k8soperator-golang
-
Create new operator
kubebuilder create api --group core --version v1 --kind ConfigMapCopy --controller --resource=false
-
Manual E2E tests
-
Make sure your target namespace exists:
kubectl create ns backup
-
Run the operator locally:
make run
-
Create a ConfigMap in the
defaultnamespace:kubectl create configmap demo --from-literal=foo=bar
-
Logs should show:
📄 Created backup ConfigMap source=default/demo copy=backup/demo-copy
-
Sanity Check:
kubectl get cm -n backup
-
-
Deployment of the
K8s Operatormake docker-build IMG=norbix/demo2-k8soperator-golang:latest && \ sleep 3 && \ make docker-push IMG=norbix/demo2-k8soperator-golang:latest && \ sleep 3 && \ make deploy IMG=norbix/demo2-k8soperator-golang:latest && \ kubectl get all -n demo2-k8soperator-golang-system
✅ Summary
You now have a fully functional operator that:
-
Watches all ConfigMaps
-
Copies them into a backup namespace
-
Keeps them in sync
-
Avoids infinite loops