Project Structure
Understanding the k8s-provisioner codebase
Execution Flow
cmd/ (Cobra commands)
└─ internal/provisioner/provisioner.go ← orchestrates all steps
└─ internal/installer/*.go ← one installer per component
└─ internal/executor/executor.go ← every shell command goes through here
config.yaml is loaded in cmd/root.go, validated, and passed to every installer.
Directory Layout
k8s-provisioner/
├── cmd/ # CLI commands (Cobra)
│ ├── root.go # Loads config.yaml, wires the executor (--dry-run)
│ ├── provision.go # provision common|init|controlplane|worker|workloads|all
│ ├── status.go # Cluster status, version
│ ├── user.go # User management (X.509 + RBAC)
│ ├── vault.go # Vault token / status / get / set / unseal
│ └── vbox.go # VirtualBox promiscuous mode
├── internal/
│ ├── config/ # config.yaml parser + validation
│ ├── executor/ # Shell executor (+ dry-run null object)
│ ├── provisioner/ # Orchestration: InstallCommon → … → InstallWorkloads
│ │ ├── provisioner.go
│ │ ├── hostprep.go # swap, kernel modules, sysctl, DNS, timezone, CRI-O
│ │ └── hostsetup.go # Exports the lab CAs and prints the host setup commands
│ ├── installer/ # One installer per component (manifests as Go strings)
│ │ ├── installer.go # Installer interface + ordered workload steps
│ │ ├── timeouts.go # Poll/timeout constants (no fixed sleeps)
│ │ ├── calico.go istio.go metallb.go metrics.go nfs_provisioner.go
│ │ ├── cert_manager.go # Self-signed lab CA + one TLS certificate per Gateway
│ │ ├── external_dns.go # Publishes Gateway hosts to the storage-node DNS (etcd)
│ │ ├── keycloak*.go # OIDC IdP: deploy, realm, gateway, oidc (apiserver), grafana SSO
│ │ ├── vault*.go vault_secrets_operator.go secrets.go
│ │ ├── monitoring*.go # Prometheus, Grafana, Alertmanager, exporters, Istio scrape,
│ │ │ # kubelet/cAdvisor, DNS + TLS probes, SLOs, k8s-lab dashboard
│ │ ├── dashboards/ # k8s-lab dashboard sections (JSON, embedded in the binary)
│ │ ├── loki.go tempo.go kiali.go # Logs, traces, mesh observability
│ │ ├── keda.go vpa.go # Autoscaling
│ │ └── karpor.go ollama.go # Explorer + AI backend (opt-in)
│ ├── user/ # User management: cert, rbac, kubeconfig, store
│ └── version/ # Build-time version injection
├── vagrant/
│ ├── Vagrantfile # Builds the Linux binary, boots 4 VMs, runs provision
│ ├── settings.yaml # VM definitions (CPU/RAM/IP per node)
│ ├── scripts/storage-dns.sh # Lab DNS on the storage node (etcd + CoreDNS, mTLS)
│ └── clean.sh # Destroys the lab and cleans leftovers
├── examples/ # Sample apps and guides
├── docs/logo/ # Project logo (SVG) and social preview
├── config.yaml # Single source of truth (versions, CIDRs, toggles, nodes)
├── VERSION # Release version (read by the auto-release workflow)
├── .golangci.yaml # Linter configuration (golangci-lint v2)
└── main.go go.mod Makefile
Key Design Decisions
| Decision | Why |
|---|---|
Manifests as Go strings, applied with kubectl | Versions and settings come from config.yaml; no templating layer to learn. Helm only for a few upstream charts |
| Vault and the lab DNS outside the cluster | Secrets and DNS records survive vagrant destroy of the Kubernetes VMs |
| Polling with timeouts, never fixed sleeps | Steps continue as soon as a component is ready, and fail clearly when it never is |
| Role detection by hostname | provision all looks up the hostname in config.yaml nodes: |
All shell calls through executor | Tests swap in a fake; --dry-run prints instead of running |
| Native API server OIDC (no proxy) | kubeadm owns the API server, so no privileged impersonation proxy is needed |
Installer Pattern
Each component is a struct built with New<Component>(cfg, executor) and exposes Install(). Installers:
- Build YAML manifests as Go strings and pipe them to
kubectl apply -f - - Poll with the timeouts in
timeouts.goinstead of sleeping - Run every subprocess through
executor.RunShell/RunShellWithOutput
The workload steps run in dependency order: MetalLB → Istio → cert-manager → Metrics Server → VPA → KEDA → NFS → Vault → VSO → ExternalDNS → Prometheus/Grafana → Loki → Tempo → Kiali → Keycloak → Ollama → Karpor.
Building
Requires Go 1.27+ and make.
make deps # download modules
make build # current platform → build/k8s-provisioner
make build-all # all 5 platforms
make build-darwin-arm64 # or build-darwin-amd64, build-linux-amd64, build-linux-arm64, build-windows-amd64
make test # go test ./...
make version # version, commit and build date
golangci-lint run ./... # lint (golangci-lint v2)
| Binary | Platform |
|---|---|
k8s-provisioner-darwin-arm64 | macOS Apple Silicon |
k8s-provisioner-darwin-amd64 | macOS Intel |
k8s-provisioner-linux-arm64 | Linux ARM64 |
k8s-provisioner-linux-amd64 | Linux x64 |
k8s-provisioner-windows-amd64.exe | Windows x64 |