Where does K8s store the logs that it prints when running kubectl logs -f

Viewed 48
  1. I am pretty sure it writes it on disk somewhere. Otherwise if the container runs for several hours and logs a lot, then it would exceed what the stderr can hold I think. No?
  2. Is it possible to compress and download the logs of kubectl logs?i.e. comparess on the container without downloading them?
1 Answers

Firstly take a look on logging-kubernetes official documentation.

In most cases, Docker container logs are put in the /var/log/containers directory on your host (host they are deployed on). Docker supports multiple logging drivers but Kubernetes API does not support driver configuration.

Once a container terminates or restarts, kubelet keeps its logs on the node. To prevent these files from consuming all of the host’s storage, a log rotation mechanism should be set on the node.

You can use kubectl logs to retrieve logs from a previous instantiation of a container with --previous flag, in case the container has crashed.

If you want to take a look at additional logs. For example, in Linux journald logs can be retrieved using the journalctl command:

$ journalctl -u docker

You can implement cluster-level logging and expose or push logs directly from every application but the implementation for such a logging mechanism is not in the scope of Kubernetes.

Also there are many tools offered for Kubernetes for logging management and aggregation - see: logs-tools.

Related