<p>I have a python application that is running in Kubernetes. The app has a ping health-check which is called frequently via a REST call and checks that the call returns an HTTP 200. This clutters the Kubernetes logs when I view it through the logs console.</p>

<p>The function definition looks like this:</p>

<pre><code>def ping():
    return jsonify({'status': 'pong'})
</code></pre>

<p>How can I silence a specific call from showing up in the log? Is there a way I can put this in code such as a python decorator on top of the health check function? Or is there an option in the Kubernetes console where I can configure to ignore this call?</p>

William Ross
<p>In kubernetes, everything in container which you have on <code>stdout</code> or <code>stderr</code> will come into the kubernetes logs. The only way to exclude the logs of <code>health-check</code> ping call remove from kubernetes logs is that, In your application you should redirect output of those ping calls to somefile in say <code>/var/log/</code>. This will effectively remove the output of that <code>health-check</code> ping from the <code>stdout</code>.</p>

<p>Once the output is not in <code>stdout</code> or <code>stderr</code> of the pods, pod logs will not have logs from that special <code>health-check</code></p>

<p>You can also use the sidecar containers to streamline your application logs, like if you don't want all of the logs of application in <code>kubectl logs</code> output. You can write those file.</p>

<p>As stated in Official docs of kubernetes:</p>

<blockquote>
  <p>By having your sidecar containers stream to their own stdout and stderr streams, you can take advantage of the kubelet and the logging agent that already run on each node. The sidecar containers read logs from a file, a socket, or the journald. Each individual sidecar container prints log to its own stdout or stderr stream.</p>
</blockquote>

<p>This approach allows you to separate several log streams from different parts of your application, some of which can lack support for writing to stdout or stderr. The logic behind redirecting logs is minimal, so it’s hardly a significant overhead.</p>

<p>For more information on Kubernetes logging, please refer official docs:</p>

<p><a href="https://kubernetes.io/docs/concepts/cluster-administration/logging/" rel="noreferrer">https://kubernetes.io/docs/concepts/cluster-administration/logging/</a></p>
