This repository demonstrates a scalable object identification application, emphasizing scalability and monitoring. The application is containerized using Docker and deployed on a local Kubernetes cluster via Minikube. Monitoring is integrated using Prometheus, and a load testing script is provided to evaluate performance under varying workloads.
-
Scalability: Designed to efficiently handle increasing workloads within a Kubernetes environment.
-
Containerization: Utilizes Docker for consistent and portable deployment across different environments.
-
Kubernetes Deployment: Deployed on Minikube, facilitating local development and testing of Kubernetes applications.
-
Monitoring: Integrated with Prometheus to collect and visualize performance metrics, aiding in proactive system management.
-
Load Testing: Includes scripts to simulate various load scenarios, enabling performance evaluation and optimization.
Before setting up the environment, ensure you have the following installed:
-
Load the Model:
python3 scripts/load_model.py
-
Configure Docker to Use Minikube's Environment:
eval $(minikube docker-env)
-
Build Docker Images:
-
Flask Application:
docker buildx build -t flask-app:latest -f ./docker/producer/Dockerfile.flaskapp . -
Worker Application:
docker buildx build -t worker-app:latest -f ./docker/consumer/Dockerfile.worker . -
Custom Autoscaler:
docker buildx build -t autoscaler:latest . -f Dockerfile.CPA
-
-
Start Minikube:
minikube start --driver=docker
Note: You can specify the number of CPU cores and memory for Minikube using the
--cpusand--memoryflags. For example:minikube start --driver=docker --cpus 4 --memory 8192
Prometheus is used for monitoring the application's performance metrics.
-
Install Prometheus Using Helm:
-
Add Helm Repository:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts helm repo update
-
Create Monitoring Namespace:
kubectl apply -f ./deployments/monitoring-namespace.yaml
-
Install Prometheus:
helm install prometheus prometheus-community/kube-prometheus-stack --namespace monitoring
This command installs Prometheus and related components into the
monitoringnamespace.
-
-
Apply Prometheus Custom Resource Definitions (CRDs):
chmod +x scripts/apply-prometheus-crds.sh ./scripts/apply-prometheus-crds.sh
-
Upgrade Prometheus with Custom Configuration:
helm upgrade prometheus prometheus-community/kube-prometheus-stack -f deployments/prometheus.yaml -n monitoring
Deploy the Flask application using the provided Kubernetes manifests:
kubectl apply -f deployments/app.yaml-
Ensure the Default Horizontal Pod Autoscaler (HPA) Is Not Active:
kubectl delete hpa flask-app-hpa
-
Deploy the Custom Autoscaler:
kubectl apply -f ./deployments/autoscaler.yaml
To access the deployed application:
-
Start Minikube Tunnel:
minikube tunnel
-
Verify Deployment:
- Open a web browser and navigate to http://localhost:5000 to access the application.
- Access Minikube Dashboard:
minikube dashboardThis command opens the Kubernetes dashboard, providing an overview of the cluster's resources and deployments.
- Access Prometheus UI:
kubectl port-forward service/prometheus-kube-prometheus-prometheus 9090:9090 -n monitoringNavigate to http://localhost:9090 in your web browser to access the Prometheus interface.
- Access Grafana UI:
kubectl port-forward -n monitoring svc/prometheus-grafana 3000:80Open http://localhost:3000 and log in with the default credentials:
-
Username: admin
-
Password: prom