This project demonstrates how to containerize a simple Flask-based machine learning API, deploy it to a Kubernetes cluster with Minikube, and serve predictions through a /predict endpoint.
- Flask API for serving ML model predictions
- Docker containerization
- Kubernetes deployment via Minikube
- RESTful
/predictendpoint - Local testable setup with curl/Postman
- SSH-authenticated GitHub repository
.
├── app.py # Flask API app
├── model.pkl # Serialized ML model (generated)
├── generate_model.py # Script to create model.pkl
├── requirements.txt # Python dependencies
├── Dockerfile # Image definition
├── deployment.yaml # Kubernetes deployment config
├── service.yaml # Kubernetes service config
└── .gitignore
git clone git@github.com:kevinmastascusa/flask-k8s-deploy.git
cd flask-k8s-deploypip install -r requirements.txt
python generate_model.pydocker build -t kzmastascusa/flask-model-api:latest .
docker push kzmastascusa/flask-model-api:latestminikube start
kubectl apply -f deployment.yaml
kubectl apply -f service.yamlminikube service flask-api-serviceYou’ll get a URL like http://127.0.0.1:64893
Request
curl -X POST http://127.0.0.1:64893/predict -H "Content-Type: application/json" -d '{"features": [1, 2]}'Response
{
"prediction": 0
}Kevin Mastascusa
🧑💻 GitHub: @kevinmastascusa
MIT License – free to use, share, or build on.