An example python flask application with prometheus monitoring on kubernetes.
351
See src for the application code.
Note: Adapted for Kubernetes from Swarm example code here: python-prometheus-demo. Original swarm prometheus article here.
Run this locally in docker:
docker run -p 8888:8888 stevenacoffman/flask_kubernetes_example
Apply this to your Kubernetes cluster (Note: cluster not included):
kubectl apply -f flask-example.yaml
The Python 3 based Dockerfile uses an Alpine Linux base image
and expects the application source code to be volume mounted at /application
when run:
FROM python:3.6.1-alpine
ADD . /application
WORKDIR /application
RUN set -e; \
apk add --no-cache --virtual .build-deps \
gcc \
libc-dev \
linux-headers \
; \
pip install -r src/requirements.txt; \
apk del .build-deps;
EXPOSE 8888
VOLUME /application
CMD uwsgi --http :8888 --manage-script-name --mount /application=flask_app:app --enable-threads --processes 5
The last statement shows how we are running the application via uwsgi with 5
worker processes.
To build the image:
$ docker build -t stevenacoffman/flask_kubernetes_example .
We can just run the web application as follows:
$ docker run -ti -p 8888:8888 stevenacoffman/flask_kubernetes_example
See the compose directory for a way to run the flask app and a prometheus server locally via docker compose
$ kubectl apply -f flask-k8s.yaml
Content type
Image
Digest
Size
32 MB
Last updated
about 7 years ago
docker pull stevenacoffman/flask_kubernetes_example