<p>So I made a very simple flask-based app and hosted it in a kubernetes pod.</p>
<p>When I open the logs in Rancher, I can see this warning:</p>
<pre><code> * Serving Flask app &quot;app/preapproved_limits/api.py&quot;
 * 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

</code></pre>
<p>that I see as well when I start flask on my local machine.</p>
<p>But what I <strong>don't see</strong> on my local machine and <strong>do see</strong> in Rancher is this:</p>
<pre><code>10.0.67.20 - - [02/Jul/2020 16:49:20] &quot;GET /health HTTP/1.1&quot; 200 -
INFO:werkzeug:10.0.67.20 - - [02/Jul/2020 16:49:20] &quot;GET /health HTTP/1.1&quot; 200 -
</code></pre>
<p>which gets logged every 5 seconds.
What the heck?</p>
<p>But the most important and annoying thing is I can't see my logs which I make with the Python's <code>print()</code> function.</p>
<p>Can someone explain:</p>
<ul>
<li>Why do I see something both in Rancher and locally (the initial Flask warning), but</li>
<li>why do I see something only in Rancher (the <code>/health</code> or <code>INFO:werkzeug</code> logs)</li>
<li>and why do I see something only locally on my machine, but not in Rancher (<code>print()</code>)</li>
</ul>

<p><code>/health</code> is a normal healthcheck endpoint that k8s needs.</p>
<p>Flask doesn't print to stdout by default because it buffers lines to make I/O more efficient. You can either call <code>sys.stdout.flush()</code>, <code>print(flush=True)</code>, set env var <code>PYTHONUNBUFFERED=1</code> in your Dockerfile (probably the easiest) or just use <code>logging</code> module as we all should.</p>
<p>You can read more about this env var <a href="https://docs.python.org/3/using/cmdline.html#cmdoption-u" rel="nofollow noreferrer">here</a>.</p>
