Project Structure
Understanding the k8s-provisioner codebase
Directory Layout
k8s-provisioner/
├── cmd/ # CLI commands
│ ├── root.go # Root command and flags
│ ├── provision.go # Provision subcommands
│ ├── status.go # Status command
│ ├── user.go # User management commands
│ └── vbox.go # VirtualBox management
├── internal/
│ ├── config/ # YAML config parser
│ │ └── config.go # Configuration structs
│ ├── executor/ # Shell command executor
│ │ └── executor.go # Command execution helpers
│ ├── installer/ # Component installers
│ │ ├── calico.go # Calico CNI
│ │ ├── metallb.go # MetalLB LoadBalancer
│ │ ├── istio.go # Istio Service Mesh
│ │ ├── monitoring.go # Prometheus + Grafana
│ │ ├── metrics.go # Metrics Server
│ │ ├── nfs_provisioner.go # NFS Dynamic Provisioner
│ │ ├── karpor.go # Karpor Explorer
│ │ └── ollama.go # Ollama AI Backend
│ └── provisioner/ # Main provisioning logic
│ └── provisioner.go # Orchestrates installation
├── vagrant/ # Vagrant configuration
│ ├── Vagrantfile # VM definitions
│ ├── settings.yaml # VM settings (IPs, RAM, CPUs)
│ └── clean.sh # Cleanup script
├── examples/ # Example manifests
│ ├── nfs-pv-pvc.yaml # NFS storage examples
│ ├── podinfo-app.yaml # Podinfo with Istio
│ └── karpor-usage.md # Karpor usage guide
├── build/ # Compiled binaries (gitignored)
├── config.yaml # Cluster configuration
├── go.mod # Go module definition
├── go.sum # Go dependencies
├── main.go # Entry point
├── Makefile # Build targets
├── VERSION # Current version
└── README.md # Project documentation
Key Components
cmd/ - CLI Layer
Uses Cobra for CLI structure:
| File | Description |
|---|---|
root.go | Main command, global flags |
provision.go | provision common, controlplane, worker, all |
status.go | Cluster status display |
user.go | User create, list, delete |
vbox.go | VirtualBox promiscuous mode |
internal/config/ - Configuration
Parses config.yaml into Go structs:
type Config struct {
Cluster ClusterConfig
Versions VersionsConfig
Network NetworkConfig
Storage StorageConfig
Nodes []NodeConfig
Components ComponentsConfig
KarporAI KarporAIConfig
Ollama OllamaConfig
}
internal/installer/ - Component Installers
Each component has its own installer:
| Installer | Component |
|---|---|
calico.go | Calico CNI |
metallb.go | MetalLB + IP Pool |
istio.go | Istio + Ingress Gateway |
monitoring.go | Prometheus Operator + Grafana + Loki |
metrics.go | Metrics Server |
nfs_provisioner.go | NFS Dynamic Provisioner |
karpor.go | Karpor + Helm |
ollama.go | Ollama + Model Pull |
internal/provisioner/ - Orchestration
provisioner.go orchestrates the installation order:
- Common packages (CRI-O, kubeadm, kubelet)
- Control plane initialization
- CNI (Calico)
- LoadBalancer (MetalLB)
- Service Mesh (Istio)
- Metrics Server
- NFS Provisioner
- Monitoring Stack
- Karpor + Ollama (if enabled)
Building
Prerequisites
- Go 1.22+
- Make
Build Commands
# Install dependencies
make deps
# Build for current platform
make build
# Build for all platforms
make build-all
# Build for specific platform
make build-darwin-arm64
make build-linux-amd64
make build-windows-amd64
# Run tests
make test
# Run linter
make lint
# Show current version
make version
Output Binaries
Binaries are placed in build/:
| 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 |