Deployment Guide
The API Reliability Suite is designed to be cloud-native and highly portable, utilizing Docker for containerization and Kubernetes for orchestration.
馃惓 Containerization
Dockerfile
The project uses a multi-stage Docker build to minimize the final image size and reduce the attack surface.
- Stage 1 (Builder): Installs Poetry and downloads all dependencies.
- Stage 2 (Runtime): Copies only the installed packages and the
src/directory into a slim Python 3.12 image.
Building the Image
鈽革笍 Kubernetes (Infrastructure as Code)
Production-ready manifests are located in infra/k8s/. These manifests follow the 2026 Reliability Standards for high-availability APIs.
1. Deployment (deployment.yaml)
The deployment ensures at least 2 replicas are always running.
- Probes: Includes both
livenessProbeandreadinessProbepointing to the/healthendpoint to ensure the cluster only sends traffic to healthy pods. - Resources: Sets explicit CPU and Memory requests/limits to prevent resource contention.
- Metrics: Annotated for automatic Prometheus scraping.
2. Auto-scaling (hpa.yaml)
A HorizontalPodAutoscaler is configured to scale the API based on CPU utilization.
- Min/Max: Scales between 2 and 10 pods.
- Target: Triggers scaling when average CPU utilization hits 70%.
- Stability: Includes a
stabilizationWindowSecondsof 300 to prevent "flapping" (rapid scaling up and down during minor load fluctuations).
Applying to Cluster
馃搳 Observability Stack
When deploying to a cluster, ensure the following services are available (or use the provided docker-compose.yml for local testing):
- Prometheus: Scrapes metrics from the
/metricsendpoint. - Jaeger: Receives distributed traces via the OTLP exporter (if
OTLP_ENDPOINTis configured). - Grafana: Visualizes the "Golden Signals" (Latency, Errors, Traffic, Saturation).
馃殌 CI/CD Integration
The provided Docker and K8s assets are designed to integrate seamlessly with CI/CD runners (GitHub Actions, GitLab CI).
- Build: Create the image using the multi-stage Dockerfile.
- Push: Push the image to your private registry (ECR, GCR, ACR).
- Deploy: Update the
imagefield ininfra/k8s/deployment.yamland apply.