A comprehensive deployment of a Flask-based Quiz Application on Kubernetes, featuring user roles, quiz management, and automated testing capabilities.
This project demonstrates deploying a scalable web application using Kubernetes. The application is a quiz platform that supports:
- Different user roles (admin, teacher, student)
- Quiz creation and management
- Timed quiz sessions
- Results tracking and analytics
- Persistent data storage
- Backend: Python Flask
- Database: SQLite with persistent storage
- Containerization: Docker
- Orchestration: Kubernetes (Minikube)
- Authentication: Flask-Login
- Docker Desktop
- Minikube
- kubectl
- Python 3.9+
- PowerShell (for Windows) or Bash (for Linux/macOS)
The application is deployed with the following Kubernetes resources:
- Deployment: 3 replicas of the Quiz App container
- Service: NodePort service exposing the application
- ConfigMap: Environment variables configuration
- Secret: Sensitive data storage (credentials, keys)
- PersistentVolume & PVC: For database persistence
- HorizontalPodAutoscaler: Auto-scales based on CPU utilization (2-5 pods)
git clone https://github.com/yourusername/quiz-app-kubernetes.git
cd quiz-app-kubernetesminikube start --memory=2048 --cpus=2 --driver=docker# For PowerShell
& minikube -p minikube docker-env | Invoke-Expressiondocker build -t quiz-app:v1 .# Apply Kubernetes manifests
kubectl apply -f k8s/pv-pvc.yaml
kubectl apply -f k8s/configmap.yaml
kubectl apply -f k8s/secret.yaml
kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/hpa.yaml
# Enable metrics-server for HPA
minikube addons enable metrics-serverminikube service quiz-app-service --urlAlternatively, run the provided deployment script:
# For PowerShell
.\deploy.ps1# Check if the service is available
kubectl get services
# Test application endpoint
minikube service quiz-app-service --url# Watch the HPA
kubectl get hpa -w
# Generate load in another terminal
kubectl run --rm -it --image=busybox load-generator -- /bin/sh -c "while true; do wget -q -O- http://quiz-app-service; done"
# Watch the pods increase
kubectl get pods -w# Build a new version
docker build -t quiz-app:v2 .
# Perform a rolling update
kubectl set image deployment/quiz-app quiz-app=quiz-app:v2
# Check rollout status
kubectl rollout status deployment/quiz-app# Rollback to previous version
kubectl rollout undo deployment/quiz-app
# Check rollback status
kubectl rollout status deployment/quiz-app# Delete a pod and watch Kubernetes recreate it
kubectl delete pod $(kubectl get pods -l app=quiz-app -o jsonpath="{.items[0].metadata.name}")
kubectl get pods -w# Create data, delete pod, verify data persists after pod recreation# View application logs
kubectl logs $(kubectl get pods -l app=quiz-app -o jsonpath="{.items[0].metadata.name}")- Username:
admin - Password:
admin123
- Administrator: Manages users (add/remove teachers and students)
- Teacher: Creates quizzes, views results, analyzes performance
- Student: Takes quizzes, views personal history and scores
- deployment.yaml: Defines the application deployment with 3 replicas
- service.yaml: Exposes the application via NodePort
- configmap.yaml: Stores environment variables
- secret.yaml: Stores sensitive data (encoded)
- pv-pvc.yaml: Defines persistent storage for the database
- hpa.yaml: Configures auto-scaling based on CPU utilization
# Delete all resources
kubectl delete -f k8s/
# OR
kubectl delete all --all
# Stop Minikube
minikube stopquiz-app-kubernetes/
├── app.py # Main Flask application
├── requirements.txt # Python dependencies
├── Dockerfile # Container definition
├── .dockerignore # Docker build exclusions
├── deploy.ps1 # Deployment automation
├── templates/ # HTML templates
├── k8s/ # Kubernetes manifests
│ ├── deployment.yaml
│ ├── configmap.yaml
│ ├── secret.yaml
│ ├── pv-pvc.yaml
│ └── hpa.yaml
Issue: Pods stuck in Pending state Solution: Check PersistentVolume provisioning or resource constraints
Issue: HPA not scaling pods
Solution: Verify metrics-server is enabled (minikube addons enable metrics-server)
Issue: Cannot access application
Solution: Ensure service is properly configured and use minikube service quiz-app-service