大网数据广告活动
服务器运维问答

How long kubernetes stores pod stdout logs?

· 52CE 我爱测

I run pods in kubernetes (1.17.0) that write logs to stdout. This pods are going to be up for a long time. I use promtail to gather logs and send to loki storage. So I can configure to store logs, for example, for last 7 days. Ho…

问题原文

原帖链接 · Kostya Regent · CC BY-SA 4.0

I run pods in kubernetes (1.17.0) that write logs to stdout. This pods are going to be up for a long time. I use promtail to gather logs and send to loki storage. So I can configure to store logs, for example, for last 7 days.

However, I don't clearly understand how kubernetes tracks these logs? I know that kubernetes deletes logs when pod is evicted, but my pods will not be evicted. That means kubernetes will store all logs and eventially node's SSD will be full? How can I configure kubernetes to delete old logs?

已采纳解答

原帖链接 · acid_fuji · CC BY-SA 4.0

Looking at the Logging architecture from the official k8s documentation there are some options:

First one is logging at node level:

Kubernetes currently 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 application’s logs automatically, for example by using Docker’s log-opt. In the kube-up.sh script, the latter approach is used for COS image on GCP, and the former approach is used in any other environment. In both cases, by default rotation is configured to take place when log file exceeds 10MB.

Second one is a sidecar container with logging agent:

Sidecar containers can also be used to rotate log files that cannot be rotated by the application itself. An example of this approach is a small container running logrotate periodically. However, it’s recommended to use stdout and stderr directly and leave rotation and retention policies to the kubelet. Good example of the logrotator can be found here.

Alternatively you can always setup your log retention policy at docker level by specifying appropriate flags. Check out docker docs for that.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-05-26)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。