This project is a step-by-step tutorial for DevOps and SRE engineers to learn about building Golang applications and Kubernetes controllers. Each step is implemented as a feature branch and includes a README section with explanations and command history.
Roadmap
This tutorial guides you through building a production-grade Golang Kubernetes controller, step by step:
Golang CLI Application using Cobra — Initialize a CLI app with cobra-cli.
Zerolog for Log Levels — Add structured logging with zerolog.
pflag for Log Level Flags — Integrate pflag for CLI log level flags.
FastHTTP Server Command — Add a server command with configurable port and log level.
Makefile, Dockerfile, and GitHub Workflow — Introduce build automation, secure containerization, CI/CD, and tests.
List Kubernetes Deployments with client-go — List deployments in the default namespace.
Deployment Informer with client-go — Watch and log Deployment events.
/deployments JSON API Endpoint — Serve deployment names as JSON from the informer cache.
controller-runtime Deployment Controller — Reconcile Deployments and log events.
Leader Election and Metrics — Add HA and metrics endpoint to the controller manager.
FrontendPage CRD and Advanced Controller — Define a custom resource and manage Deployments/ConfigMaps.
Platform API (CRUD + Swagger) — Add RESTful CRUD API and Swagger UI.
MCP Integration — Integrate MCP server for multi-cluster management.
JWT Authentication — Secure API endpoints with JWT.
OpenTelemetry Instrumentation — Add distributed tracing with OpenTelemetry.
Dev Environment (GitHub Codespaces)
Recommended way:
develop and test your code with envtest k8s control plane first (we use it on step7)
test controller with local kind cluster (find example)
deploy controller as helm chart in production cluster (use helm chart from step10)
#### Install brew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
### Install kind
brew install kind
### Install K9S for cluster management
curl -sS https://webi.sh/k9s | sh
### Create kind cluster
kind create cluster
### Add some usefull aliases
alias kk="EDITOR='code --wait' k9s"
alias k=kubectl
## Run complete controller setup
go run main.go