Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to silence log message in Kubernetes?

Tags:

kubernetes

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?

like image 401
William Ross Avatar asked Jan 03 '19 14:01

William Ross


People also ask

How do you clear logs in Kubernetes?

You can't, the log rotation is generally implemented in Docker (or sometimes via logrotate on the node host). However you can use kubectl logs --since-time and fill in the time of your last get.

What is kubectl logs command?

It's as simple as this: kubectl logs [pod_name] The above command will show you the logs of the application running in the container. By default, the application will log to STDOUT and STDERR inside the container. Then, kubectl logs will show you the output of these two streams.

How do I monitor logs in Kubernetes?

The most basic form of logging in Kubernetes is the output generated by individual containers using stdout and stderr. The output for the current running container instance is available to be accessed via the kubectl logs command. The next level up of logging in the Kubernetes world is called node level logging.


1 Answers

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/

like image 87
Prafull Ladha Avatar answered Sep 28 '22 10:09

Prafull Ladha