A step-by-step guide for running a Flask web application containerized with Docker and deployed on Kubernetes.
- Project Overview
- Prerequisites
- Project Structure
- Setup and Run Locally
- Dockerization
- Kubernetes Deployment
- Accessing the App
- Next Steps / Enhancements
- License
This project demonstrates how to:
- Develop a simple Flask web app
- Containerize it using Docker
- Deploy it to a Kubernetes cluster (Minikube / EKS / GKE)
- Make it production-ready with Gunicorn
Make sure you have the following installed:
- Python 3.12
- Docker
- Kubernetes CLI (
kubectl) - Minikube (for local cluster testing)
Optional:
- Helm for advanced deployment
- GitHub / Docker Hub account for pushing images
mini-flask-app/
├── application.py # Flask app
├── templates/
│ └── index.html # HTML page rendered by Flask
├── requirements.txt # Python dependencies
├── Dockerfile # Container definition
└── README.md
- Create a virtual environment (optional):
python -m venv venv
source venv/bin/activate # Linux/Mac
venv\Scripts\activate # Windows- Install dependencies:
pip install -r requirements.txt- Run the Flask app:
python application.pyVisit: http://127.0.0.1:5000
- Build Docker image:
docker build -t mini_app:v1.0 .
- Test locally:
docker run -p 5000:5000 mini_app:v1.0- Push to Docker Hub:
docker tag mini_app:v1.0 <dockerhub-username>/mini_app:v1.0
docker push <dockerhub-username>/mini_app:v1.0
- Start Minikube:
minikube start
- Create a deployment:
kubectl create deployment miniapp --image=<dockerhub-username>/mini_app:v1.0- Expose the deployment:
kubectl expose deployment miniapp --type=NodePort --port=5000- Check pods:
kubectl get pods
- Get service info:
kubectl get svc miniapp- Access the app:
- For Minikube:
minikube service miniapp
- Or open in browser:
http://<minikube-ip>:<nodeport>
- Pod IPs are internal and not accessible from outside the cluster.
- Use NodePort or Ingress to access externally.
- Example NodePort URL:
http://192.168.49.2:32698
- Add liveness and readiness probes for health checks
- Implement Ingress + TLS for domain access
- Automate deployment using CI/CD pipelines (GitHub Actions / ArgoCD)
- Scale horizontally using replicas
This project is open-source and free to use under the MIT License.