Keeping Flask Applications alive with Kuber Liveness Probes

10/11/2018

I have a Flask server which needs to do some CPU heavy tasks, and some routes need around 1.5 seconds to answer. Additionally, Kubernetes makes regular checks on liveness using one of the API endpoints.

If I make a penalty test for my API and give it a lot of requests per seconds, the container regularly crashes, because the liveness probe cannot be answered. This also happens when using async gunicorn gevent workers. If the workload gets too high, the liveness probe requests needs to long to be answered.

I thought about reserving a gunicorn worker just for the liveness probe, but it doesn't seem to be possible to do that within gunicorn. It feels like I'm overcomplicating things a little bit. Does somebody know how this sort of problem is usually solved?

-- TheWaveLad
flask
gunicorn
kubernetes
python

0 Answers