K8s limit for pod logs

Viewed 1196

When I try to retrieve logs from my pods, I note that K8s does not print all the logs, and I know that because I observe that logs about microservice initialization are not present in the head of logs.

Considering that my pods print a lot of logs in a long observation period, does someone know if K8s has a limit in showing all logs?

I also tried to set --since parameter in the kubectl logs command to get all logs in a specific time range, but it seems to have no effect.

Thanks.

3 Answers

The container runtime engine typically manages container (pod) logs. Do check the settings on the runtime engine in use.

There are some answers, I'll add more details and sources.

The answer is quite short. There is no limit but free space. By default kubernetes is not responsible for log rotation:

An important consideration in node-level logging is implementing log rotation, so that logs don't consume all available storage on the node. Kubernetes is not responsible for rotating logs, but rather a deployment tool should set up a solution to address that. For example, in Kubernetes clusters, deployed by the kube-up.sh script, there is a logrotate tool configured to run each hour. You can also set up a container runtime to rotate an application's logs automatically.

As it was stated by William, Kubernetes itself doesn’t provide log aggregation of its own and it relies on container runtime by default.

When a container running on Kubernetes writes its logs to stdout or stderr streams, they are picked up by the kubelet service running on that node, and are delegated to the container engine for handling based on the logging driver configured in Kubernetes.

In most cases, Docker container logs will end up in the /var/log/containers directory on your host. Docker supports multiple logging drivers but, unfortunately, 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.

Kubernetes doesn’t provide built-in log rotation, but this functionality is available in many tools, such as Docker’s log-opt, or standard file shippers or even a simple custom cron job. When a container is evicted from the node, so are its corresponding log files

That means you can try to find full logs in /var/log/containers and var/log/pods. This part is from official documentation and more precise:

By default, if a container restarts, the kubelet keeps one terminated container with its logs. If a pod is evicted from the node, all corresponding containers are also evicted, along with their logs.

To have a good visibility and accessibility of logs you may consider having a dedicated solution for logs storing. E.g. node logging agent or streaming to a sidecar

Please find articles and official kubernetes documentation with concepts and examples:

Related