π§° Project Overview
This project demonstrates how to:
β’ Containerize a simple Flask web app and a mock database API
β’ Deploy both services using Kubernetes
β’ Use inter-service communication inside the cluster
β’ Access the frontend via browser and retrieve data from the backend
π¦** Project Structure**
π§ Prerequisites
β’ Docker
β’ Minikube
β’ kubectl
β’ A basic understanding of Python and terminal commands
*Step 1: Create the Flask Apps
Web/app.py (file)
*
π db/app.py
π³ Step 2: Dockerize the Apps
π web/Dockerfile
π db/Dockerfile
π requirements.txt (for both)
π§ͺ Step 3: Build Docker Images in Minikube
RUN:
minikube start
eval $(minikube docker-env)
Then build:
docker build -t flask-web ./web
docker build -t flask-db ./db
**
π§Ύ Step 4: Create Kubernetes Deployment & Service Files
**
π db-deployment.yaml
π web-deployment.yaml
π Step 5: Deploy to Kubernetes
kubectl apply -f db-deployment.yaml
kubectl apply -f web-deployment.yaml
Check the status:
kubectl get pods
kubectl get services
π Step 6: Access the Web App
minikube service web-service --url
*I went on to improve the project by adding monitoring and logging *
β
Monitoring using Prometheus + Grafana
β
Logging using Loki + Grafana
*Goal *
Prometheus - Collect metrics (CPU, memory, HTTP request)
Grafana - Visualize metrics and logs
Loki - Collect and search logs
π§± Prerequisites
Make sure you have:
β’ Minikube
β’ kubectl
β’ Your web and db services already deployed
β’ Optional: Helm (weβll use it for easier installation)
*Part 1: Monitoring with Prometheus + Grafana *
β
Step 1: Enable Helm in Minikube (optional but recommended)
**
minikube addons enable helm-tiller
**
β
Step 2: Add Helm Repos
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
β Step 3: Install Prometheus
helm install prometheus prometheus-community/prometheus
This installs:
β’ Prometheus server
β’ Node exporter
β’ Alertmanager
Check it: kubectl get pods
**
β
Step 4: Install Grafana**
helm install grafana grafana/grafana \
--set adminPassword='admin' \
--set service.type=NodePort
Find the Grafana service:
minikube service grafana --url
Log in with:
β’ User: admin
β’ Password: admin
β Step 5: Add Prometheus as Data Source in Grafana
- Open Grafana (from minikube service grafana)
- Go to Settings > Data Sources
- Click Add Data Source
- Choose Prometheus
- URL: http://prometheus-server
- Click Save & Test Now youβre ready to build dashboards! ** β Step 6: Add Metrics to Your Flask Apps (Optional but recommended) ** Add prometheus_flask_exporter to both web/requirements.txt and db/requirements.txt:
Flask
requests
prometheus_flask_exporter
Update both app.py files:
from prometheus_flask_exporter import PrometheusMetrics
metrics = PrometheusMetrics(app)
Rebuild and redeploy the images:
eval $(minikube docker-env)
docker build -t flask-web ./web
docker build -t flask-db ./db
kubectl rollout restart deployment web
kubectl rollout restart deployment db
Top comments (0)