How to silence log message in Kubernetes?

1/3/2019

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.

The function definition looks like this:

def ping():
    return jsonify({'status': 'pong'})

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?

-- William Ross
kubernetes

2 Answers

1/9/2019

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

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

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 kubectl logs output. You can write those file.

As stated in Official docs of kubernetes:

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.

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.

For more information on Kubernetes logging, please refer official docs:

https://kubernetes.io/docs/concepts/cluster-administration/logging/

-- Prafull Ladha
Source: StackOverflow

1/7/2019

Just invert the logic log on fail in the app, modify the code or wrap with a custom decorator

-- ms4720
Source: StackOverflow