This repository contains a minimal Go HTTP API intended for deployment to a small Kubernetes cluster. It uses gin and exposes a few endpoints useful for demos, probes and Prometheus scraping.
Endpoints
- GET / — service name, version, hostname, time
- GET /healthz — liveness probe (always 200 if process alive)
- GET /readyz — readiness probe (returns 200 only when DB reachable)
- GET /env — shows a small subset of config values (from
ConfigMap) - GET /work?ms=200 — sleeps N ms to simulate latency
- GET /kill — simulates a crash (panics the process)
- GET /metrics — Prometheus metrics
Build & run (local)
go mod tidy
make build
SERVICE_NAME=sample-app VERSION=0.1.0 DB_HOST=localhost DB_USER=postgres DB_PASSWORD=password DB_NAME=postgres ./bin/sample-appDocker
make docker-build
docker run --rm -p 8080:8080 -e DB_HOST=localhost -e DB_USER=postgres -e DB_PASSWORD=password -e DB_NAME=postgres sample-app:localKubernetes (example)
kubectl apply -f k8s/configmap.yaml
kubectl apply -f k8s/secret.yaml
kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/service.yamlNotes
- The app expects a Postgres-compatible database configured via environment variables (DB_HOST, DB_USER, DB_PASSWORD, etc.) or a full DB_DSN. For real clusters put credentials in a
Secretand reference via env. - The readiness probe calls
db.Ping()with a small timeout; if the DB is unreachable the pod will show NotReady.