https://github.com/stevenacoffman/flask_kubernetes_example
Simple Kubernetes Flask application
https://github.com/stevenacoffman/flask_kubernetes_example
docker flask kubernetes prometheus python
Last synced: 2 months ago
JSON representation
Simple Kubernetes Flask application
- Host: GitHub
- URL: https://github.com/stevenacoffman/flask_kubernetes_example
- Owner: StevenACoffman
- License: mit
- Created: 2017-09-29T19:29:17.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-08-25T00:39:52.000Z (almost 3 years ago)
- Last Synced: 2025-03-18T05:40:08.575Z (about 1 year ago)
- Topics: docker, flask, kubernetes, prometheus, python
- Language: Shell
- Homepage: https://hub.docker.com/r/stevenacoffman/flask_kubernetes_example/
- Size: 18.6 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Example Flask app with Prometheus on Kubernetes
See ``src`` for the application code.
Note: Adapted for Kubernetes from Swarm example code here: [python-prometheus-demo](https://github.com/amitsaha/python-prometheus-demo/). Original [swarm prometheus article](https://blog.codeship.com/monitoring-your-synchronous-python-web-applications-using-prometheus/?utm_content=58060028&utm_medium=social&utm_source=twitter) here.
Run this locally in docker:
```bash
docker run -p 8888:8888 stevenacoffman/flask_kubernetes_example
```
Apply this to your Kubernetes cluster (Note: cluster not included):
```bash
kubectl apply -f flask-example.yaml
```
## Building Docker image
The Python 3 based [Dockerfile](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 .
```
## Running the application
We can just run the web application as follows:
```
$ docker run -ti -p 8888:8888 stevenacoffman/flask_kubernetes_example
```
## Running the application via Docker compose
See the compose directory for a way to run the flask app and a prometheus server locally via docker compose
## Running the application via Kubernetes
```
$ kubectl apply -f flask-k8s.yaml
```