So I made a very simple flask-based app and hosted it in a kubernetes pod.
When I open the logs in Rancher, I can see this warning:
* Serving Flask app "app/preapproved_limits/api.py"
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
that I see as well when I start flask on my local machine.
But what I don't see on my local machine and do see in Rancher is this:
10.0.67.20 - - [02/Jul/2020 16:49:20] "GET /health HTTP/1.1" 200 -
INFO:werkzeug:10.0.67.20 - - [02/Jul/2020 16:49:20] "GET /health HTTP/1.1" 200 -
which gets logged every 5 seconds. What the heck?
But the most important and annoying thing is I can't see my logs which I make with the Python's print()
function.
Can someone explain:
/health
or INFO:werkzeug
logs)print()
) /health
is a normal healthcheck endpoint that k8s needs.
Flask doesn't print to stdout by default because it buffers lines to make I/O more efficient. You can either call sys.stdout.flush()
, print(flush=True)
, set env var PYTHONUNBUFFERED=1
in your Dockerfile (probably the easiest) or just use logging
module as we all should.
You can read more about this env var here.