Skip to content

norbix/demo2_k8soperator_golang

Repository files navigation

demo2_k8soperator_golang

Demo application containing Kubernetes (K8s) Operator solution in pure Golang.

Prerequisites

Entire playbook assumes that you are using Windows 11 OS and PowerShell as CLI and in some stages Linux WSL.

Getting Started

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
  1. Manually install the prerequisites

    • kubebuilder

      mkdir -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, and docker

      Versions:

      # 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
      
  2. Clone the repository

    cd <path/to/codebase>/
    git clone https://github.com/norbix/demo2_k8soperator_golang.git
    
  3. Start Docker Desktop

    Start-Process "C:\Program Files\Docker\Docker\Docker Desktop.exe" -WindowStyle Minimized
  4. Start K8s cluster

    kind 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
  5. Scaffold project

    kubebuilder init --domain norbix.io --repo github.com/norbix/demo2-k8soperator-golang --project-name demo2-k8soperator-golang
  6. Create new operator

    kubebuilder create api --group core --version v1 --kind ConfigMapCopy --controller --resource=false
  7. Manual E2E tests

    • Make sure your target namespace exists:

      kubectl create ns backup
    • Run the operator locally:

      make run
    • Create a ConfigMap in the default namespace:

      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
  8. Deployment of the K8s Operator

    make 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

About

Demo application containing Kubernetes (K8s) Operator solution in pure Golang.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published