A lightweight Flask-based streaming catalog API backed by PostgreSQL, designed for both Docker Compose and Kubernetes deployments.
The repository is organized around a Kubernetes-native topology that makes the runtime model easy to reason about:
flowchart TD
NS[Namespace: streaming-service]
NS --> DEPLOY[Deployment: streaming-api]
DEPLOY --> HPA[HorizontalPodAutoscaler]
NS --> STATEFUL[StatefulSet: streaming-db]
DEPLOY --> NP[NetworkPolicy]
STATEFUL --> PVC[PersistentVolumeClaim]
NS --> CM[ConfigMap + Secret]
- Namespace: isolates the streaming-service workload.
- Deployment: runs the Flask API as a horizontally scalable frontend tier.
- HPA: automatically scales the API pods based on CPU and memory utilization.
- StatefulSet: runs PostgreSQL with stable storage for movie data.
- NetworkPolicy: constrains ingress and egress traffic between the API and database.
- Docker Desktop or Docker Engine
- Docker Compose v2
docker compose up --build -dcurl http://localhost:5000/healthExpected response:
{
"status": "healthy",
"database": "connected"
}docker compose downCreate a movie:
curl -X POST http://localhost:5000/api/movies \
-H "Content-Type: application/json" \
-d '{
"code": "MOV1234567",
"title": "The Matrix",
"director": "Lana Wachowski",
"year": 1999,
"duration": 136,
"genres": ["Action", "Sci-fi"],
"language": "English",
"rating": 8.7,
"seasons": 0,
"rental_cost": 3.99
}'List movies:
curl http://localhost:5000/api/moviesSearch movies:
curl "http://localhost:5000/api/movies/search?q=matrix"The Kubernetes manifests live in the yaml directory.
kubectl apply -f yaml/01-namespace-configmap-secret.yamlkubectl apply -f yaml/02-deployment-service.yamlkubectl get pods -n streaming-service
kubectl get svc -n streaming-serviceThe deployment exposes the API through a LoadBalancer service on port 80, mapped to the Flask app on port 5000.
| Method | Endpoint | Description | Status |
|---|---|---|---|
| GET | /health | Health check for the API and database connection | 200 / 503 |
| GET | / | Service metadata and available routes | 200 |
| POST | /api/movies | Create a new movie | 201 / 400 / 409 |
| GET | /api/movies | List all movies or fetch one by code using ?code=... | 200 / 404 |
| GET | /api/movies/search?q=... | Search movies by code, title, director, genres, or language | 200 / 400 |
| PUT | /api/movies/ |
Update supported movie fields | 200 / 400 / 404 |
| DELETE | /api/movies/ |
Delete a movie by code | 200 / 404 |
Run the pytest suite:
pytest -qsrc/ Flask application and SQLAlchemy models
config/ environment-specific config
database/ SQL init scripts for local Postgres
docker/ container build files
yaml/ Kubernetes manifests
tests/ pytest coverage for the API