A containerized Python Flask application demonstrating application packaging, Docker-based deployment, Kubernetes orchestration, and offline Python dependency installation.
This project demonstrates how to package and deploy a Python Flask application using modern containerization and orchestration tools.
The application can be built and executed using Docker, managed through Docker Compose, and deployed to a Kubernetes cluster.
An additional focus of this project is offline dependency management. Python packages are stored locally in the packages/ directory, allowing dependencies to be installed without downloading them from the internet.
The following diagram illustrates the high-level application architecture:
flowchart TD
User[Client / Browser]
App[Flask Application]
Runtime[Python Runtime]
Dependencies[Python Dependencies]
User --> App
App --> Runtime
Runtime --> Dependencies
| Technology | Purpose |
|---|---|
| Python 3.12 | Application runtime |
| Flask | Web application framework |
| Docker | Application containerization |
| Docker Compose | Container lifecycle management |
| Kubernetes | Container orchestration |
| Kubernetes Deployment | Application workload management |
| Kubernetes Service | Internal application networking |
| Kubernetes Ingress | External HTTP routing |
| pip | Python dependency management |
- Python Flask web application.
- Docker image build and container execution.
- Docker Compose configuration.
- Kubernetes Deployment, Service, and Ingress manifests.
- Offline Python dependency installation using locally stored wheel packages.
- Separation of application code and deployment configuration.
.
├── app/
│ └── main.py
├── packages/
│ └── Python wheel packages
├── k8s/
│ ├── deployment.yaml
│ ├── service.yaml
│ └── ingress.yaml
├── Dockerfile
├── docker-compose.yml
├── requirements.txt
├── ci_generate_html.py
└── README.md
This project includes locally stored Python packages in the packages/ directory.
Install dependencies using the local package repository:
pip install --no-index --find-links=packages -r requirements.txtThis approach is useful in restricted environments where direct access to public package repositories is unavailable.
Build the Docker image:
docker build -t python-flask-devops .Run the container:
docker run -d --name flask-app python-flask-devopsThe container port and host port mapping should follow the port configuration defined in the Dockerfile and application.
Build and start the application using Docker Compose:
docker compose up -d --buildCheck running containers:
docker compose psStop the application:
docker compose downThe Kubernetes manifests are available in the k8s/ directory.
Apply the manifests:
kubectl apply -f k8s/Check the deployed resources:
kubectl get deployments
kubectl get pods
kubectl get services
kubectl get ingressCheck application logs:
kubectl logs <pod-name>The Ingress resource requires a compatible Ingress Controller to be installed and configured in the Kubernetes cluster.
flowchart TD
Source[Python Application Source]
Dockerfile[Dockerfile]
Image[Docker Image]
Compose[Docker Compose]
K8s[Kubernetes Manifests]
Deployment[Kubernetes Deployment]
Pod[Application Pod]
Service[Kubernetes Service]
Ingress[Kubernetes Ingress]
User[External Client]
Source --> Dockerfile
Dockerfile --> Image
Image --> Compose
Image --> Deployment
Deployment --> Pod
User --> Ingress
Ingress --> Service
Service --> Pod
Application and deployment settings are maintained in the corresponding project files:
requirements.txt: Python dependencies.Dockerfile: Container image build instructions.docker-compose.yml: Local container orchestration.k8s/deployment.yaml: Kubernetes workload configuration.k8s/service.yaml: Kubernetes networking configuration.k8s/ingress.yaml: External HTTP routing configuration.
Check Docker containers:
docker ps -aInspect container logs:
docker logs flask-appCheck Kubernetes resources:
kubectl get allInspect a Kubernetes Pod:
kubectl describe pod <pod-name>Potential improvements for this project include:
- CI/CD pipeline integration.
- Container image vulnerability scanning.
- Kubernetes resource limits and health probes.
- Application monitoring and centralized logging.
- Helm-based Kubernetes deployment.
- Automated deployment validation.
This project focuses on practical DevOps skills, including:
- Application containerization.
- Docker-based deployment.
- Kubernetes resource management.
- Offline dependency management.
- Deployment configuration and troubleshooting.
| Document | Description |
|---|---|
| Architecture | Application and infrastructure architecture |
| Deployment Guide | Docker and Kubernetes deployment instructions |
| CI/CD Strategy | Proposed CI/CD workflow and future improvements |
- Containerized Python Flask application.
- Docker and Docker Compose deployment.
- Kubernetes workload orchestration.
- Offline Python dependency installation.
- Infrastructure and deployment documentation.
Mahbod Rahimian
DevOps Engineer | Infrastructure Automation | Containerization | Kubernetes