This project provides a robust, production-ready template for deploying a Python FastAPI application with a MySQL backend on OpenShift. Originating as an exam assignment to fetch data via a GET request, this project has been significantly expanded to showcase a complete, best-practice architecture for building and deploying cloud-native microservices.
The entire infrastructure is defined using declarative Kubernetes manifests and can be deployed automatically with a single script for both Linux/macOS and Windows.
- Full CRUD API: The API was extended from a single
GETendpoint to full Create, Read, Update, and Delete functionality. - Modular API Architecture: Uses FastAPI's
APIRouterto keep API logic clean, organized, and scalable. - High-Performance DAL: Implements a MySQL Connection Pool in the Data Access Layer (DAL) to handle concurrent requests efficiently.
- Declarative Infrastructure (IaC): All OpenShift/Kubernetes resources are defined in standardized YAML manifests.
- Advanced Configuration Management: Clear separation between non-sensitive configuration (
ConfigMap) and secrets (Secret). - Reliability & Health Monitoring: Includes liveness and readiness probes for both the API and the database to ensure service stability and automated recovery.
- Resource Management: Defines CPU and memory
requestsandlimitsto guarantee performance and prevent resource starvation in a shared environment. - Full Automation: Provides cross-platform deployment scripts (
.shand.bat) for a complete, one-command setup.
- Backend: Python 3.11 with FastAPI & Pydantic
- Database: MySQL 8.0
- Containerization: Docker
- Orchestration: OpenShift / Kubernetes
- Database Driver:
mysql-connector-python
The project is organized into distinct directories, each with its own detailed documentation.
.
├── infrastructure/
│ └── k8s/
│ ├── README.md # (Hebrew) In-depth explanation of all YAML manifests
│ └── ... # All Kubernetes/OpenShift YAML manifests
├── scripts/
│ ├── commands.sh # Automated deployment script for Linux/macOS
│ └── commands.bat # Automated deployment script for Windows
├── services/
│ └── data_loader/
│ ├── routers/ # FastAPI APIRouter for CRUD operations
│ ├── README.md # (Hebrew) In-depth explanation of the Python code architecture
│ ├── data_loader.py # Data Access Layer (DAL) with Connection Pooling
│ ├── main.py # Main FastAPI application entrypoint
│ └── models.py # Pydantic data models
├── Dockerfile # Dockerfile for the FastAPI app
├── demo_guide.md # Step-by-step manual deployment guide (Hebrew)
└── README.md # This file
- Python Code Architecture: A detailed, educational walkthrough of the Python application's structure, from a basic implementation to the final production-ready design. (Hebrew)
- Kubernetes Manifests Explained: A breakdown of each YAML file, explaining its role in the overall infrastructure. (Hebrew)
For a quick setup, use the provided automation scripts.
- Access to an OpenShift cluster and the
ocCLI. - A Docker Hub account (
docker loginexecuted). - Docker Desktop (or Docker daemon) running.
Run the appropriate script from the scripts/ directory, providing your Docker Hub username as the first argument.
# Make the script executable
chmod +x scripts/commands.sh
# Run the deployment
./scripts/commands.sh your-dockerhub-username.\scripts\commands.bat your-dockerhub-usernameThe script will build the image, deploy all resources, initialize the database, and print the final application URL.
For a detailed, step-by-step guide with explanations for each command, ideal for presentations or learning, please refer to the manual deployment guide.
➡️ Click here to view the Manual Deployment Guide (demo_guide.md)
This guide is in Hebrew and provides separate commands for different operating systems.