This repository contains a Flask microservices application that demonstrates deploying a Flask app on Azure Kubernetes Service (AKS) using Helm. The application uses Gunicorn as the WSGI server and includes health checks, system information endpoints, and more.
- Prerequisites
- Setup
- Build and Push Docker Image
- Deploy to AKS
- Verify Deployment
- Usage
- Cleanup
- Troubleshooting
- Azure CLI: Install the Azure CLI. Follow the instructions here.
- Kubectl: Install kubectl. Follow the instructions here.
- Helm: Install Helm. Follow the instructions here.
- Docker: Install Docker. Follow the instructions here.
- Python 3.10: Ensure Python 3.10 is installed on your machine.
-
Clone the Repository:
git clone <repository-url> cd <repository-directory>
-
Create a Virtual Environment and Install Dependencies:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate` pip install -r requirements.txt
-
Login to Azure and ACR:
az login az acr login --name <acr-name>
-
Build the Docker Image:
docker build -t flask-microservices-demo . -
Tag the Docker Image:
docker tag flask-microservices-demo <acr-login-server>/flask-microservices-demo:1.0.0 docker tag flask-microservices-demo <acr-login-server>/flask-microservices-demo:latest
-
Push the Docker Image to ACR:
docker push <acr-login-server>/flask-microservices-demo:1.0.0 docker push <acr-login-server>/flask-microservices-demo:latest
-
Create AKS Cluster (if not already created):
chmod +x create_aks_cluster.sh ./infra/provision-aks-cni-overlay.sh
-
Set the Default Namespace:
kubectl create namespace mynamespace kubectl config set-context --current --namespace=mynamespace
-
Update Helm Values: Ensure your
values.yamlin the Helm chart uses the correct ACR repository and image tag.image: repository: <acr-login-server>/flask-microservices-demo tag: "1.0.0" pullPolicy: IfNotPresent
-
Deploy the Helm Chart:
helm upgrade --install flask-app ./flask-app-0.2.0.tgz --namespace mynamespace --create-namespace
-
Check the Status of the Deployment:
kubectl get deployments kubectl get services kubectl get pods
-
Get the External IP of the Service:
kubectl get svc flask-service
Access the application using the external IP address.
-
Endpoints:
GET /: Returns "Hello, World!"GET /health: Returns the health status of the application.GET /details: Returns the hostname and IP address of the pod.GET /env: Returns environment variables.GET /time: Returns the current server time.GET /network: Returns network details of the pod.GET /system-info: Returns CPU, memory, and disk usage.GET /random-joke: Returns a random joke.
-
Access the Application: Open your browser and navigate to the external IP address of the service.
To delete the resources created for this deployment, run the following commands:
-
Uninstall the Helm Release:
helm uninstall flask-app --namespace mynamespace
-
Delete the AKS Cluster:
az aks delete --resource-group <resource-group> --name <cluster-name> --yes --no-wait
If you encounter issues, check the following:
-
Check Pod Logs:
kubectl logs <pod-name> -n mynamespace
-
Describe the Pod:
kubectl describe pod <pod-name> -n mynamespace
-
Ensure All Services are Running:
kubectl get all -n mynamespace
-
Check the Helm Release Status:
helm status flask-app --namespace mynamespace
For additional troubleshooting, refer to the Kubernetes and Helm documentation.
This project is provided "as-is" without any warranty or guarantee of any kind. Use at your own risk. The authors and maintainers are not responsible for any damages or issues that may arise from using this project.
Replace placeholder values like `<repository-url>`, `<acr-name>`, `<acr-login-server>`, `<resource-group>`, and `<cluster-name>` with the actual values relevant to your environment. This `README.md` provides comprehensive instructions for setting up, deploying, and using your Flask application on AKS.