Skip to content

A simple Python project to run a Flask application with Gunicorn on Minikube using Docker and Kubernetes. This setup includes building a Docker image and deploying the app on Minikube.

Notifications You must be signed in to change notification settings

zardazare/flask_on_k8s

Repository files navigation

Flask with Gunicorn in Minikube

This is a simple setup for running a Flask application with Gunicorn on Minikube and Docker.

Mypy Type Check

Prerequisites

Steps

  1. Build the Docker image

    docker build -f docker/Dockerfile -t flask_on_k8s:latest .
    • After building the image, add it to Minikube's cache so it’s available for deployment:
    minikube image load flask_on_k8s:latest 
    • You can verify that the image is loaded with this command:
    minikube image list

    Note: Cached images will have the docker.io/library/ prefix.

  2. Deploy to Minikube

    Apply the Kubernetes deployment and service:

    kubectl apply -f deployment/deployment.yml
    • Hint: Example for starting multiple nodes:
    minikube start --nodes 3 -p multinode-test
  3. Access the Application

    Get the URL of the service:

    minikube service flask-test-app-service --url

    Open the URL in a browser or use curl to see the response.

  4. Cleanup

    To delete the deployment and service, run:

    kubectl delete -f deployment/deployment.yml

Run Without Kubernetes

If you’d like to run the Docker container independently (outside Kubernetes) for testing, you can run it on a different external port (e.g., 9000).

Run container

  • Detached mode

    docker run -d -p 9000:5000 --name=flask_with_gunicorn_localhost flask_on_k8s:latest
  • Interactive mode

    docker run -it -p 9000:5000 --name=flask_with_gunicorn_localhost flask_on_k8s:latest sh

Useful commands

  • Execute commands in container/pod

    kubectl exec -it <pod name> -- /bin/sh
  • Restart deployment

    kubectl rollout restart deployment/flask-test-app-deployment
  • Logs from container in deployment

    kubectl logs deployment/flask-test-app-deployment -c flask-test-app

Monitoring Setup

For detailed instructions on setting up and configuring the monitoring tools, check out the Monitoring Documentation.

About

A simple Python project to run a Flask application with Gunicorn on Minikube using Docker and Kubernetes. This setup includes building a Docker image and deploying the app on Minikube.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published