Skip to content

Commit 0627c35

Browse files
authored
Merge pull request kubernetes#93781 from kisieland/allow-to-switch-off-logrotate
Disable log rotation of kubernetes and pod logs
2 parents c7d6f79 + adf7ed4 commit 0627c35

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

cluster/gce/config-default.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,13 +425,20 @@ METADATA_CLOBBERS_CONFIG="${METADATA_CLOBBERS_CONFIG:-false}"
425425

426426
ENABLE_BIG_CLUSTER_SUBNETS="${ENABLE_BIG_CLUSTER_SUBNETS:-false}"
427427

428+
# Optional: Enable log rotation for k8s services
429+
ENABLE_LOGROTATE_FILES="${ENABLE_LOGROTATE_FILES:-false}"
430+
PROVIDER_VARS="${PROVIDER_VARS:-} ENABLE_LOGROTATE_FILES"
428431
if [[ -n "${LOGROTATE_FILES_MAX_COUNT:-}" ]]; then
429432
PROVIDER_VARS="${PROVIDER_VARS:-} LOGROTATE_FILES_MAX_COUNT"
430433
fi
431434
if [[ -n "${LOGROTATE_MAX_SIZE:-}" ]]; then
432435
PROVIDER_VARS="${PROVIDER_VARS:-} LOGROTATE_MAX_SIZE"
433436
fi
434437

438+
# Optional: Enable log rotation for pod logs
439+
ENABLE_POD_LOG="${ENABLE_POD_LOG:-false}"
440+
PROVIDER_VARS="${PROVIDER_VARS:-} ENABLE_POD_LOG"
441+
435442
if [[ -n "${POD_LOG_MAX_FILE:-}" ]]; then
436443
PROVIDER_VARS="${PROVIDER_VARS:-} POD_LOG_MAX_FILE"
437444
fi

cluster/gce/config-test.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,13 +467,20 @@ ADVANCED_AUDIT_LOG_MODE=${ADVANCED_AUDIT_LOG_MODE:-batch} # batch, blocking
467467

468468
ENABLE_BIG_CLUSTER_SUBNETS=${ENABLE_BIG_CLUSTER_SUBNETS:-false}
469469

470+
# Optional: Enable log rotation for k8s services
471+
ENABLE_LOGROTATE_FILES="${ENABLE_LOGROTATE_FILES:-false}"
472+
PROVIDER_VARS="${PROVIDER_VARS:-} ENABLE_LOGROTATE_FILES"
470473
if [[ -n "${LOGROTATE_FILES_MAX_COUNT:-}" ]]; then
471474
PROVIDER_VARS="${PROVIDER_VARS:-} LOGROTATE_FILES_MAX_COUNT"
472475
fi
473476
if [[ -n "${LOGROTATE_MAX_SIZE:-}" ]]; then
474477
PROVIDER_VARS="${PROVIDER_VARS:-} LOGROTATE_MAX_SIZE"
475478
fi
476479

480+
# Optional: Enable log rotation for pod logs
481+
ENABLE_POD_LOG="${ENABLE_POD_LOG:-false}"
482+
PROVIDER_VARS="${PROVIDER_VARS:-} ENABLE_POD_LOG"
483+
477484
if [[ -n "${POD_LOG_MAX_FILE:-}" ]]; then
478485
PROVIDER_VARS="${PROVIDER_VARS:-} POD_LOG_MAX_FILE"
479486
fi

cluster/gce/gci/configure-helper.sh

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -439,17 +439,19 @@ function ensure-local-ssds() {
439439
# Installs logrotate configuration files
440440
function setup-logrotate() {
441441
mkdir -p /etc/logrotate.d/
442-
# Configure log rotation for all logs in /var/log, which is where k8s services
443-
# are configured to write their log files. Whenever logrotate is ran, this
444-
# config will:
445-
# * rotate the log file if its size is > 100Mb OR if one day has elapsed
446-
# * save rotated logs into a gzipped timestamped backup
447-
# * log file timestamp (controlled by 'dateformat') includes seconds too. This
448-
# ensures that logrotate can generate unique logfiles during each rotation
449-
# (otherwise it skips rotation if 'maxsize' is reached multiple times in a
450-
# day).
451-
# * keep only 5 old (rotated) logs, and will discard older logs.
452-
cat > /etc/logrotate.d/allvarlogs <<EOF
442+
443+
if [[ "${ENABLE_LOGROTATE_FILES:-false}" = "true" ]]; then
444+
# Configure log rotation for all logs in /var/log, which is where k8s services
445+
# are configured to write their log files. Whenever logrotate is ran, this
446+
# config will:
447+
# * rotate the log file if its size is > 100Mb OR if one day has elapsed
448+
# * save rotated logs into a gzipped timestamped backup
449+
# * log file timestamp (controlled by 'dateformat') includes seconds too. This
450+
# ensures that logrotate can generate unique logfiles during each rotation
451+
# (otherwise it skips rotation if 'maxsize' is reached multiple times in a
452+
# day).
453+
# * keep only 5 old (rotated) logs, and will discard older logs.
454+
cat > /etc/logrotate.d/allvarlogs <<EOF
453455
/var/log/*.log {
454456
rotate ${LOGROTATE_FILES_MAX_COUNT:-5}
455457
copytruncate
@@ -463,9 +465,11 @@ function setup-logrotate() {
463465
create 0644 root root
464466
}
465467
EOF
468+
fi
466469

467-
# Configure log rotation for pod logs in /var/log/pods/NAMESPACE_NAME_UID.
468-
cat > /etc/logrotate.d/allpodlogs <<EOF
470+
if [[ "${ENABLE_POD_LOG:-false}" = "true" ]]; then
471+
# Configure log rotation for pod logs in /var/log/pods/NAMESPACE_NAME_UID.
472+
cat > /etc/logrotate.d/allpodlogs <<EOF
469473
/var/log/pods/*/*.log {
470474
rotate ${POD_LOG_MAX_FILE:-5}
471475
copytruncate
@@ -479,6 +483,7 @@ EOF
479483
create 0644 root root
480484
}
481485
EOF
486+
fi
482487
}
483488

484489
# Finds the master PD device; returns it in MASTER_PD_DEVICE

0 commit comments

Comments
 (0)