# Installs logrotate configuration files
function setup-logrotate() {
mkdir -p /etc/logrotate.d/
# Configure log rotation for all logs in /var/log, which is where k8s services
# are configured to write their log files. Whenever logrotate is ran, this
# config will:
# * rotate the log file if its size is > 100Mb OR if one day has elapsed
# * save rotated logs into a gzipped timestamped backup
# * log file timestamp (controlled by 'dateformat') includes seconds too. This
# ensures that logrotate can generate unique logfiles during each rotation
# (otherwise it skips rotation if 'maxsize' is reached multiple times in a
# day).
# * keep only 5 old (rotated) logs, and will discard older logs.
cat > /etc/logrotate.d/allvarlogs <<EOF
/var/log/*.log {
rotate ${LOGROTATE_FILES_MAX_COUNT:-5}
copytruncate
missingok
notifempty
compress
maxsize ${LOGROTATE_MAX_SIZE:-100M}
daily
dateext
dateformat -%Y%m%d-%s
create 0644 root root
}
EOF
}
1 回答
您确定由于日志而导致磁盘的磁盘使用率很高吗?如果应用程序将日志写入stdout,则它不会使用pod中的任何磁盘空间 . 所有日志通常都存储在节点文件系统的日志文件中,并且可以由节点logrotate进程管理 .
也许应用程序使用pod的磁盘空间来处理其他内容,比如临时文件或调试信息?
以下是documentation与日志轮换相关的部分:
以下是与logrotate相关的脚本的一部分: