Using FastAPI, Docker, and Kubernetes (Minikube)
End-to-End Deployment of a Heart Disease Risk Prediction API
End-to-End Deployment of a Heart Disease Risk Prediction API
Using FastAPI, Docker, and Kubernetes (Minikube)
1. Overview
This project demonstrates the full lifecycle of a machine-learning microservice for healthcare, built and deployed using modern cloud-native tools — FastAPI, Docker, and Kubernetes — entirely locally on Windows 11.
The service predicts the probability of heart disease from patient data using a logistic regression model trained on the UCI Heart Disease dataset.
☸️ Note: It simulates a real-world production scenario where an AI model is containerized, orchestrated, and scaled automatically inside a Kubernetes cluster.
2. Project Objectives
- Build a simple but clinically relevant ML model.
- Wrap it in a FastAPI service exposing a REST API.
- Containerize the service using Docker.
- Deploy and manage it using Kubernetes (Minikube).
- Test, document, and prepare it for portfolio and GitHub presentation.
## 3. Tools & Frameworks
| Component | Purpose |
|---|---|
| Python 3.11 | Core language |
| FastAPI + Uvicorn | REST API framework |
| scikit-learn + pandas + numpy + joblib | Model training and serialization |
| Docker | Containerization |
| Kubernetes + kubectl + Minikube | Container orchestration |
| Windows 11 + PowerShell | Development environment |
4. Folder Structure
View Source Code
Click to expand interactive code modal
5. Model Training (train_model.py)
View Source Code
Click to expand interactive code modal
⚡ Note: Running this script trains a scaled logistic regression model and saves
model.pklandcolumns.jsonunderapp/.
6. FastAPI Service (app/main.py)
View Source Code
Click to expand interactive code modal
Test locally with:
View Source Code
Click to expand interactive code modal
and browse to http://127.0.0.1:8000/docs.
7. Python Requirements (requirements.txt)
View Source Code
Click to expand interactive code modal
8. Docker Containerization
Dockerfile
View Source Code
Click to expand interactive code modal
Build & Run Locally
View Source Code
Click to expand interactive code modal
Access at http://localhost:8000/docs.
9. Kubernetes Deployment (Minikube)
Start cluster:
View Source Code
Click to expand interactive code modal
Load image:
View Source Code
Click to expand interactive code modal
deployment.yaml
View Source Code
Click to expand interactive code modal
service.yaml
View Source Code
Click to expand interactive code modal
Apply:
View Source Code
Click to expand interactive code modal
Check:
View Source Code
Click to expand interactive code modal
Access the API:
View Source Code
Click to expand interactive code modal
🌐 Note: Your browser opens to something like http://127.0.0.1:31535/docs.
10. Validation
Send a JSON POST:
View Source Code
Click to expand interactive code modal
Response:
View Source Code
Click to expand interactive code modal
11. Verification & Monitoring
View logs:
View Source Code
Click to expand interactive code modal
Open dashboard:
View Source Code
Click to expand interactive code modal
12. Clean-Up
View Source Code
Click to expand interactive code modal
13. Key Outcomes
✅ Achievements:
- Fully operational healthcare microservice for heart disease risk prediction.
- Containerized and orchestrated ML workflow on local Kubernetes cluster.
- Reusable pattern for any other AI/ML healthcare API.
- No cloud cost — completely free on local hardware.