A production-ready machine learning serving platform built with Flask, Prometheus, and Kubernetes. Demonstrates enterprise-grade MLOps practices with automated deployment, monitoring, and scalability.
- Random Forest classifier with 8 financial features
- 87.5% test accuracy on profitability prediction
- Feature importance analysis (Net Income: 69.55%)
- Support for JSON object and array input formats
- Prometheus metrics collection
- Custom prediction metrics (latency, error rates, request counts)
- Real-time metrics endpoint (
/metrics) - Health & readiness probes for Kubernetes
- Docker & Docker Compose for local development
- Kubernetes deployment with rolling updates
- ArgoCD GitOps for automated deployments
- High availability (2 replicas, zero-downtime updates)
- Input validation with Pydantic v2
- Non-root container execution
- Resource limits and constraints
- RBAC-ready for Kubernetes
- Docker multi-stage builds
- Automated testing (78% coverage)
- GitOps-driven deployments
- Comprehensive monitoring setup
βββββββββββββββ
β Client β
ββββββββ¬βββββββ
β HTTP
βΌ
βββββββββββββββββββββββββββ
β Flask API (5000) β
βββββββββββββββββββββββββββ€
β β’ /predict β
β β’ /health β
β β’ /ready β
β β’ /metrics β
βββββββ¬ββββββββββββββββββββ
β Scrape
βΌ
ββββββββββββββββββββββββββββ
β Prometheus (9090) β
ββββββββββββββββββββββββββββ€
β β’ Metrics Storage β
β β’ Query Engine β
β β’ Alert Rules β
ββββββββββββββββββββββββββββ
| Component | Technology | Purpose |
|---|---|---|
| API | Flask + Gunicorn | REST API server |
| ML Model | Scikit-learn (Random Forest) | Predictions |
| Validation | Pydantic v2 | Input validation |
| Containerization | Docker | Application packaging |
| Orchestration | Kubernetes | Cluster management |
| Deployment | ArgoCD | GitOps automation |
| Monitoring | Prometheus | Metrics collection |
| Testing | Pytest | Unit testing |
Task: Binary classification (Profitability prediction)
Features (8):
- Revenue
- Gross Profit
- EBITDA
- Share Holder Equity
- Operating Expenses
- Net Income β (69.55% importance)
- Total Assets
- Total Liabilities
Performance:
- Training Accuracy: 99.38%
- Test Accuracy: 87.5%
- Class Distribution: ~50/50 balanced
- Docker & Docker Compose
- Python 3.10+
- kubectl (for Kubernetes deployment)
# Clone repository
git clone https://github.com/rabelmervin/PredictOps.git
cd PredictOps
# Run with Docker Compose
docker-compose up -d --build
# Test health
curl http://localhost:5000/health
# Make prediction
curl -X POST http://localhost:5000/predict \
-H "Content-Type: application/json" \
-d '{
"Revenue": 3000000,
"Gross Profit": 1500000,
"EBITDA": 800000,
"Share Holder Equity": 2500000,
"Operating Expenses": 300000,
"Net Income": 400000,
"Total Assets": 5000000,
"Total Liabilities": 2500000
}'
# View metrics
curl http://localhost:5000/metrics# Deploy with ArgoCD
kubectl apply -f kubernetes/argo-application.yaml
# Monitor deployment
argocd app get predictops
# Access application
kubectl port-forward svc/predictops-service 5000:80
curl http://localhost:5000/healthHealth check for load balancers.
Response:
{"status": "ok"}Readiness probe for Kubernetes.
Response:
{"ready": true}Make predictions with 8 financial features.
Request (JSON object):
{
"Revenue": 3000000,
"Gross Profit": 1500000,
"EBITDA": 800000,
"Share Holder Equity": 2500000,
"Operating Expenses": 300000,
"Net Income": 400000,
"Total Assets": 5000000,
"Total Liabilities": 2500000
}Request (JSON array):
[3000000, 1500000, 800000, 2500000, 300000, 400000, 5000000, 2500000]Response:
{"prediction": [1]}Prometheus metrics in exposition format.
# Install dependencies
pip install -r requirements.txt pytest pytest-cov
# Run tests
python -m pytest tests/test_app.py -v
# Generate coverage report
python -m pytest tests/test_app.py --cov=app --cov-report=htmlTest Coverage: 78%
- β Health endpoint
- β Readiness endpoint
- β Metrics endpoint
- β Valid predictions
- β Invalid input handling
- β Array input format
Application Metrics:
prediction_requests_total- Total predictions madeprediction_duration_seconds- Prediction latency histogramprediction_errors_total- Total prediction errors
Flask Metrics:
flask_http_request_total- HTTP requests by method/statusflask_http_request_duration_seconds- Request latency
# Raw metrics endpoint
curl http://localhost:5000/metrics
# Prometheus UI
open http://localhost:9090
# Query prediction rate
curl 'http://localhost:9090/api/v1/query?query=rate(prediction_requests_total[5m])'PredictOps/
βββ app/
β βββ app.py # Flask application
β βββ validation.py # Pydantic models
β βββ requirements.txt # Python dependencies
βββ models/
β βββ random_forest_model.joblib # Trained ML model
βββ kubernetes/
β βββ deployment.yaml # K8s deployment config
β βββ service.yaml # K8s service config
β βββ argo-application.yaml # ArgoCD config
βββ monitoring/
β βββ prometheus/
β βββ prometheus.yml
β βββ alerting_rules.yaml
βββ tests/
β βββ test_app.py # Unit tests
βββ docker-compose.yml # Local development stack
βββ Dockerfile # Container image
βββ README.md # This file
FLASK_ENV=production # Flask environment
PYTHONUNBUFFERED=1 # Real-time loggingrequests:
memory: "256Mi"
cpu: "250m"
limits:
memory: "512Mi"
cpu: "500m"docker-compose up -d --build- Single command local deployment
- Includes Prometheus monitoring
- Port: 5000 (API), 9090 (Prometheus)
kubectl apply -f kubernetes/argo-application.yaml- Automated GitOps deployments
- Zero-downtime rolling updates
- Auto-healing and self-recovery
- Revision history & rollback capability
β Production-Ready ML Model
- Trained on synthetic financial data
- 87.5% test accuracy with balanced classes
- Feature importance analysis
β Comprehensive Monitoring
- Prometheus metrics collection
- Custom application metrics
- Health & readiness probes
β Enterprise DevOps
- Docker containerization
- Kubernetes orchestration
- ArgoCD GitOps automation
β Code Quality
- 78% test coverage
- Pydantic input validation
- Security best practices
β Scalability
- 2 replicas for high availability
- Rolling updates with zero downtime
- Resource limits and constraints
import requests
response = requests.post(
'http://localhost:5000/predict',
json={
'Revenue': 3000000,
'Gross Profit': 1500000,
'EBITDA': 800000,
'Share Holder Equity': 2500000,
'Operating Expenses': 300000,
'Net Income': 400000,
'Total Assets': 5000000,
'Total Liabilities': 2500000
}
)
print(response.json()) # {'prediction': [1]}curl -X POST http://localhost:5000/predict \
-H "Content-Type: application/json" \
-d '[3000000, 1500000, 800000, 2500000, 300000, 400000, 5000000, 2500000]'| Metric | Value |
|---|---|
| API Response Time | < 50ms |
| Model Prediction Latency | < 10ms |
| Throughput | 1000+ requests/min |
| Uptime (HA) | 99.9% |
| Memory Usage | ~300MB |
- β Input validation (Pydantic v2)
- β Non-root container user
- β No privilege escalation
- β Resource limits
- β Read-only filesystem option
- β Network policies ready
Your deployment is successful when:
- β All 6 pytest tests pass
- β
/healthreturns{"status":"ok"} - β
/readyreturns{"ready":true} - β Predictions return values (0 or 1)
- β
/metricsreturns Prometheus data - β Kubernetes pods run with 2 replicas
- β ArgoCD auto-syncs from GitHub
For issues or questions:
- Review logs:
docker-compose logs -f api - Check Kubernetes events:
kubectl get events - View ArgoCD UI:
http://localhost:8080
This project is open source and available under the MIT License.
Built with β€οΈ using Flask, Kubernetes, and ArgoCD
Last Updated: November 16, 2025