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

Summary

This project demonstrates the complete end-to-end deployment of a machine learning microservice for heart disease risk prediction using a modern, cloud-native stack. A logistic regression model is wrapped in a high-performance FastAPI REST endpoint, containerized with Docker, and orchestrated locally using Kubernetes via Minikube. The resulting pipeline serves as a reproducible blueprint for deploying, managing, and scaling AI-driven healthcare APIs within a robust container orchestration environment.

Using FastAPI, Docker, and Kubernetes (Minikube)


GitHub Logo View Project on GitHub

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

  1. Build a simple but clinically relevant ML model.
  2. Wrap it in a FastAPI service exposing a REST API.
  3. Containerize the service using Docker.
  4. Deploy and manage it using Kubernetes (Minikube).
  5. Test, document, and prepare it for portfolio and GitHub presentation.


## 3. Tools & Frameworks
ComponentPurpose
Python 3.11Core language
FastAPI + UvicornREST API framework
scikit-learn + pandas + numpy + joblibModel training and serialization
DockerContainerization
Kubernetes + kubectl + MinikubeContainer orchestration
Windows 11 + PowerShellDevelopment environment

4. Folder Structure


5. Model Training (train_model.py)

Note: Running this script trains a scaled logistic regression model and saves model.pkl and columns.json under app/.



6. FastAPI Service (app/main.py)

Test locally with:

and browse to http://127.0.0.1:8000/docs.


7. Python Requirements (requirements.txt)


8. Docker Containerization

Dockerfile

Build & Run Locally

Access at http://localhost:8000/docs.


9. Kubernetes Deployment (Minikube)

Start cluster:

Load image:

deployment.yaml

service.yaml

Apply:

Check:

Access the API:

🌐 Note: Your browser opens to something like http://127.0.0.1:31535/docs.


10. Validation

Send a JSON POST:

Response:


11. Verification & Monitoring

View logs:

Open dashboard:


12. Clean-Up


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.

© Balaji Ramanathan