A Go web application demonstrating Kubernetes Horizontal Pod Autoscaling (HPA) with Prometheus metrics.
| Method | Path | Description |
|---|---|---|
| GET | /health | Health check |
| GET | /metrics | Prometheus metrics |
| POST | /load | Generate CPU load to trigger HPA scaling |
{ "amount": 4, "duration": 30 }amount— number of CPU-bound goroutines (1–64, default: number of CPUs)duration— how long to run in seconds (1–300, default: 10)
minikube start
minikube addons enable metrics-server
minikube addons enable ingressmake load-imagemake deployVerify the app is running via port-forward:
# Terminal 1 — keep open
kubectl port-forward svc/auto-scaler-service 8080:80
# Terminal 2
curl http://localhost:8080/healthNote (WSL2 / Docker driver): Ingress is not directly reachable on WSL2 with the Docker driver because NodePorts are not exposed from the minikube container. Use
kubectl port-forwardas shown above, or runminikube tunnelin a separate terminal to enable Ingress access viahttp://auto-scaler.local.
make setup-monitoringWait until all pods are running:
kubectl get pods -wAccess Grafana (credentials: admin / prom-operator):
minikube service kube-prometheus-grafanaTo get password for admin account in Grafana:
kubectl --namespace default get secrets kube-prometheus-grafana -o jsonpath="{.data.admin-password}" | base64 -d ; echoNote (WSL2): If the browser doesn't open automatically, run
minikube service kube-prometheus-grafana --urlto get the URL and open it manually.
Open three terminals:
# Terminal 1 — port-forward (keep open)
kubectl port-forward svc/auto-scaler-service 8080:80
# Terminal 2 — watch HPA react in real time
make watch-hpa
# Terminal 3 — run the load test
BASE_URL=http://localhost:8080 make load-testExpected behavior: CPU usage rises above 50% → HPA scales pods up to max 5 → load ends → pods scale back down after ~60s.
You can also see the CPU usage and amount of replicas using following command
kubectl get hpa auto-scaler-hpaInside Grafana here are the main dashboards:
- Kubernetes / Compute Resources / Workload
- Kubernetes / Compute Resources / Namespace (Workloads)
There you can track number of pods, CPU usage and other
The app exposes the following Prometheus metrics:
| Metric | Type | Description |
|---|---|---|
http_requests_total |
Counter | Total requests by method, path, status |
http_request_duration_seconds |
Histogram | Request latency |
http_requests_dropped_total |
Counter | Requests canceled or timed out |
Useful PromQL queries in Grafana (Explore → Prometheus):
# Replica count over time
kube_deployment_status_replicas{deployment="auto-scaler"}
# Requests per second
rate(http_requests_total[1m])
# Average response time
rate(http_request_duration_seconds_sum[1m]) / rate(http_request_duration_seconds_count[1m])
.
├── cmd/
│ └── main.go
├── internal/
│ ├── handlers/
│ │ ├── dto.go
│ │ ├── health.go
│ │ ├── load.go
│ │ └── metrics.go
│ └── util/
│ └── json.go
├── deploy/k8s/
│ ├── deployment.yaml
│ ├── service.yaml
│ ├── ingress.yaml
│ ├── hpa.yaml
│ └── servicemonitor.yaml
├── load-test/
│ └── load-test.js
├── Dockerfile
└── Makefile