mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Allow to disable logrotation of kubernetes and pod logs
Make logrotate disabled by default
This commit is contained in:
parent
aa0632208e
commit
adf7ed4241
@ -425,6 +425,9 @@ METADATA_CLOBBERS_CONFIG="${METADATA_CLOBBERS_CONFIG:-false}"
|
||||
|
||||
ENABLE_BIG_CLUSTER_SUBNETS="${ENABLE_BIG_CLUSTER_SUBNETS:-false}"
|
||||
|
||||
# Optional: Enable log rotation for k8s services
|
||||
ENABLE_LOGROTATE_FILES="${ENABLE_LOGROTATE_FILES:-false}"
|
||||
PROVIDER_VARS="${PROVIDER_VARS:-} ENABLE_LOGROTATE_FILES"
|
||||
if [[ -n "${LOGROTATE_FILES_MAX_COUNT:-}" ]]; then
|
||||
PROVIDER_VARS="${PROVIDER_VARS:-} LOGROTATE_FILES_MAX_COUNT"
|
||||
fi
|
||||
@ -432,6 +435,10 @@ if [[ -n "${LOGROTATE_MAX_SIZE:-}" ]]; then
|
||||
PROVIDER_VARS="${PROVIDER_VARS:-} LOGROTATE_MAX_SIZE"
|
||||
fi
|
||||
|
||||
# Optional: Enable log rotation for pod logs
|
||||
ENABLE_POD_LOG="${ENABLE_POD_LOG:-false}"
|
||||
PROVIDER_VARS="${PROVIDER_VARS:-} ENABLE_POD_LOG"
|
||||
|
||||
if [[ -n "${POD_LOG_MAX_FILE:-}" ]]; then
|
||||
PROVIDER_VARS="${PROVIDER_VARS:-} POD_LOG_MAX_FILE"
|
||||
fi
|
||||
|
@ -467,6 +467,9 @@ ADVANCED_AUDIT_LOG_MODE=${ADVANCED_AUDIT_LOG_MODE:-batch} # batch, blocking
|
||||
|
||||
ENABLE_BIG_CLUSTER_SUBNETS=${ENABLE_BIG_CLUSTER_SUBNETS:-false}
|
||||
|
||||
# Optional: Enable log rotation for k8s services
|
||||
ENABLE_LOGROTATE_FILES="${ENABLE_LOGROTATE_FILES:-false}"
|
||||
PROVIDER_VARS="${PROVIDER_VARS:-} ENABLE_LOGROTATE_FILES"
|
||||
if [[ -n "${LOGROTATE_FILES_MAX_COUNT:-}" ]]; then
|
||||
PROVIDER_VARS="${PROVIDER_VARS:-} LOGROTATE_FILES_MAX_COUNT"
|
||||
fi
|
||||
@ -474,6 +477,10 @@ if [[ -n "${LOGROTATE_MAX_SIZE:-}" ]]; then
|
||||
PROVIDER_VARS="${PROVIDER_VARS:-} LOGROTATE_MAX_SIZE"
|
||||
fi
|
||||
|
||||
# Optional: Enable log rotation for pod logs
|
||||
ENABLE_POD_LOG="${ENABLE_POD_LOG:-false}"
|
||||
PROVIDER_VARS="${PROVIDER_VARS:-} ENABLE_POD_LOG"
|
||||
|
||||
if [[ -n "${POD_LOG_MAX_FILE:-}" ]]; then
|
||||
PROVIDER_VARS="${PROVIDER_VARS:-} POD_LOG_MAX_FILE"
|
||||
fi
|
||||
|
@ -428,17 +428,19 @@ function ensure-local-ssds() {
|
||||
# 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
|
||||
|
||||
if [[ "${ENABLE_LOGROTATE_FILES:-false}" = "true" ]]; then
|
||||
# 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
|
||||
@ -452,9 +454,11 @@ function setup-logrotate() {
|
||||
create 0644 root root
|
||||
}
|
||||
EOF
|
||||
fi
|
||||
|
||||
# Configure log rotation for pod logs in /var/log/pods/NAMESPACE_NAME_UID.
|
||||
cat > /etc/logrotate.d/allpodlogs <<EOF
|
||||
if [[ "${ENABLE_POD_LOG:-false}" = "true" ]]; then
|
||||
# Configure log rotation for pod logs in /var/log/pods/NAMESPACE_NAME_UID.
|
||||
cat > /etc/logrotate.d/allpodlogs <<EOF
|
||||
/var/log/pods/*/*.log {
|
||||
rotate ${POD_LOG_MAX_FILE:-5}
|
||||
copytruncate
|
||||
@ -468,6 +472,7 @@ EOF
|
||||
create 0644 root root
|
||||
}
|
||||
EOF
|
||||
fi
|
||||
}
|
||||
|
||||
# Finds the master PD device; returns it in MASTER_PD_DEVICE
|
||||
@ -924,7 +929,7 @@ EOF
|
||||
limitedResources:
|
||||
- resource: pods
|
||||
matchScopes:
|
||||
- scopeName: PriorityClass
|
||||
- scopeName: PriorityClass
|
||||
operator: In
|
||||
values: ["system-node-critical", "system-cluster-critical"]
|
||||
EOF
|
||||
|
Loading…
Reference in New Issue
Block a user