Allow to disable logrotation of kubernetes and pod logs

Make logrotate disabled by default
This commit is contained in:
Daniel Gutowski 2020-08-07 10:26:45 +02:00 committed by Daniel Gutowski
parent aa0632208e
commit adf7ed4241
3 changed files with 33 additions and 14 deletions

View File

@ -425,6 +425,9 @@ METADATA_CLOBBERS_CONFIG="${METADATA_CLOBBERS_CONFIG:-false}"
ENABLE_BIG_CLUSTER_SUBNETS="${ENABLE_BIG_CLUSTER_SUBNETS:-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 if [[ -n "${LOGROTATE_FILES_MAX_COUNT:-}" ]]; then
PROVIDER_VARS="${PROVIDER_VARS:-} LOGROTATE_FILES_MAX_COUNT" PROVIDER_VARS="${PROVIDER_VARS:-} LOGROTATE_FILES_MAX_COUNT"
fi fi
@ -432,6 +435,10 @@ if [[ -n "${LOGROTATE_MAX_SIZE:-}" ]]; then
PROVIDER_VARS="${PROVIDER_VARS:-} LOGROTATE_MAX_SIZE" PROVIDER_VARS="${PROVIDER_VARS:-} LOGROTATE_MAX_SIZE"
fi 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 if [[ -n "${POD_LOG_MAX_FILE:-}" ]]; then
PROVIDER_VARS="${PROVIDER_VARS:-} POD_LOG_MAX_FILE" PROVIDER_VARS="${PROVIDER_VARS:-} POD_LOG_MAX_FILE"
fi fi

View File

@ -467,6 +467,9 @@ ADVANCED_AUDIT_LOG_MODE=${ADVANCED_AUDIT_LOG_MODE:-batch} # batch, blocking
ENABLE_BIG_CLUSTER_SUBNETS=${ENABLE_BIG_CLUSTER_SUBNETS:-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 if [[ -n "${LOGROTATE_FILES_MAX_COUNT:-}" ]]; then
PROVIDER_VARS="${PROVIDER_VARS:-} LOGROTATE_FILES_MAX_COUNT" PROVIDER_VARS="${PROVIDER_VARS:-} LOGROTATE_FILES_MAX_COUNT"
fi fi
@ -474,6 +477,10 @@ if [[ -n "${LOGROTATE_MAX_SIZE:-}" ]]; then
PROVIDER_VARS="${PROVIDER_VARS:-} LOGROTATE_MAX_SIZE" PROVIDER_VARS="${PROVIDER_VARS:-} LOGROTATE_MAX_SIZE"
fi 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 if [[ -n "${POD_LOG_MAX_FILE:-}" ]]; then
PROVIDER_VARS="${PROVIDER_VARS:-} POD_LOG_MAX_FILE" PROVIDER_VARS="${PROVIDER_VARS:-} POD_LOG_MAX_FILE"
fi fi

View File

@ -428,17 +428,19 @@ function ensure-local-ssds() {
# Installs logrotate configuration files # Installs logrotate configuration files
function setup-logrotate() { function setup-logrotate() {
mkdir -p /etc/logrotate.d/ 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 if [[ "${ENABLE_LOGROTATE_FILES:-false}" = "true" ]]; then
# config will: # Configure log rotation for all logs in /var/log, which is where k8s services
# * rotate the log file if its size is > 100Mb OR if one day has elapsed # are configured to write their log files. Whenever logrotate is ran, this
# * save rotated logs into a gzipped timestamped backup # config will:
# * log file timestamp (controlled by 'dateformat') includes seconds too. This # * rotate the log file if its size is > 100Mb OR if one day has elapsed
# ensures that logrotate can generate unique logfiles during each rotation # * save rotated logs into a gzipped timestamped backup
# (otherwise it skips rotation if 'maxsize' is reached multiple times in a # * log file timestamp (controlled by 'dateformat') includes seconds too. This
# day). # ensures that logrotate can generate unique logfiles during each rotation
# * keep only 5 old (rotated) logs, and will discard older logs. # (otherwise it skips rotation if 'maxsize' is reached multiple times in a
cat > /etc/logrotate.d/allvarlogs <<EOF # day).
# * keep only 5 old (rotated) logs, and will discard older logs.
cat > /etc/logrotate.d/allvarlogs <<EOF
/var/log/*.log { /var/log/*.log {
rotate ${LOGROTATE_FILES_MAX_COUNT:-5} rotate ${LOGROTATE_FILES_MAX_COUNT:-5}
copytruncate copytruncate
@ -452,9 +454,11 @@ function setup-logrotate() {
create 0644 root root create 0644 root root
} }
EOF EOF
fi
# Configure log rotation for pod logs in /var/log/pods/NAMESPACE_NAME_UID. if [[ "${ENABLE_POD_LOG:-false}" = "true" ]]; then
cat > /etc/logrotate.d/allpodlogs <<EOF # Configure log rotation for pod logs in /var/log/pods/NAMESPACE_NAME_UID.
cat > /etc/logrotate.d/allpodlogs <<EOF
/var/log/pods/*/*.log { /var/log/pods/*/*.log {
rotate ${POD_LOG_MAX_FILE:-5} rotate ${POD_LOG_MAX_FILE:-5}
copytruncate copytruncate
@ -468,6 +472,7 @@ EOF
create 0644 root root create 0644 root root
} }
EOF EOF
fi
} }
# Finds the master PD device; returns it in MASTER_PD_DEVICE # Finds the master PD device; returns it in MASTER_PD_DEVICE