This is a simple setup for running a Flask application with Gunicorn on Minikube and Docker.
-
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. -
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
-
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.
-
Cleanup
To delete the deployment and service, run:
kubectl delete -f deployment/deployment.yml
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
).
-
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
-
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
For detailed instructions on setting up and configuring the monitoring tools, check out the Monitoring Documentation.