Skip to content

hariscats/simple-python-microservices

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flask Microservices Demo on K8s

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.

Table of Contents

Prerequisites

  1. Azure CLI: Install the Azure CLI. Follow the instructions here.
  2. Kubectl: Install kubectl. Follow the instructions here.
  3. Helm: Install Helm. Follow the instructions here.
  4. Docker: Install Docker. Follow the instructions here.
  5. Python 3.10: Ensure Python 3.10 is installed on your machine.

Setup

  1. Clone the Repository:

    git clone <repository-url>
    cd <repository-directory>
  2. 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

Build and Push Docker Image

  1. Login to Azure and ACR:

    az login
    az acr login --name <acr-name>
  2. Build the Docker Image:

    docker build -t flask-microservices-demo .
  3. 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
  4. 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

Deploy to AKS

  1. Create AKS Cluster (if not already created):

    chmod +x create_aks_cluster.sh
    ./infra/provision-aks-cni-overlay.sh
  2. Set the Default Namespace:

    kubectl create namespace mynamespace
    kubectl config set-context --current --namespace=mynamespace
  3. Update Helm Values: Ensure your values.yaml in 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
  4. Deploy the Helm Chart:

    helm upgrade --install flask-app ./flask-app-0.2.0.tgz --namespace mynamespace --create-namespace

Verify Deployment

  1. Check the Status of the Deployment:

    kubectl get deployments
    kubectl get services
    kubectl get pods
  2. Get the External IP of the Service:

    kubectl get svc flask-service

    Access the application using the external IP address.

Usage

  1. 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.
  2. Access the Application: Open your browser and navigate to the external IP address of the service.

Cleanup

To delete the resources created for this deployment, run the following commands:

  1. Uninstall the Helm Release:

    helm uninstall flask-app --namespace mynamespace
  2. Delete the AKS Cluster:

    az aks delete --resource-group <resource-group> --name <cluster-name> --yes --no-wait

Troubleshooting

If you encounter issues, check the following:

  1. Check Pod Logs:

    kubectl logs <pod-name> -n mynamespace
  2. Describe the Pod:

    kubectl describe pod <pod-name> -n mynamespace
  3. Ensure All Services are Running:

    kubectl get all -n mynamespace
  4. Check the Helm Release Status:

    helm status flask-app --namespace mynamespace

For additional troubleshooting, refer to the Kubernetes and Helm documentation.

Disclaimer

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published