Skip to content

Playground to build a simple Go API with token postgres dependency and deploy it to k8s in a local k8s cluster using flux

Notifications You must be signed in to change notification settings

mhever/sample-app

Repository files navigation

sample-app — tiny Go HTTP service

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-app

Docker

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:local

Kubernetes (example)

kubectl apply -f k8s/configmap.yaml
kubectl apply -f k8s/secret.yaml
kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/service.yaml

Notes

  • 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 Secret and reference via env.
  • The readiness probe calls db.Ping() with a small timeout; if the DB is unreachable the pod will show NotReady.

About

Playground to build a simple Go API with token postgres dependency and deploy it to k8s in a local k8s cluster using flux

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors 2

  •  
  •