How to Modify Logrotation Period in Management Plane
Problem
Based on the volume of logs being produced, at times it is required to modify the log rotation frequency of files associated with kubelet, kube-apiserver, kube-scheduler etc in the nodes.
Environment
- Platform9 Edge Cloud - v5.3 and Higher
Answer
To modify the log rotation days, it is possible to edit the file: /etc/logrotate.d/pf9-<respective_file_name> for the maxage and rotate directives.
In logrotate, both maxage and rotate directives are used to manage the retention of rotated log files, but the function in slightly different ways:
- maxage Directive: The maxage directive specifies the maximum age (in days) of rotated log files to retain. It determines how long rotated log files should be kept before they are removed. This directive helps enforce a specific time-based retention policy for log files. For example, if the maxage 7 is configured for a log file, logrotate will delete rotated log files that are older than seven days. It ensures that only the most recent rotated log files within the defined timeframe are retained, while older log files are automatically purged.
- rotate Directive: The rotate directive specifies the number of rotated log files to keep. It determines the maximum number of log files (including the current and rotated ones) that should be retained before the oldest log files are removed. This directive helps enforce a space-based retention policy for log files.
For instance, if the rotate 10 is configured for a log file, logrotate will keep a maximum of ten log files (including the current log file) and delete the oldest log file once the limit is reached. As new log files are generated, logrotate will rotate and compress them, ensuring that the total number of log files does not exceed the specified limit.
In summary, maxage focuses on the age of the rotated log files and specifies how long to retain them based on the number of days, while rotate focuses on the number of log files to retain and specifies the maximum number of log files to keep, regardless of their age.
The default log rotation period for kubelet, kube-APIServer, kube-Scheduler, kube-controller-manager are 10 days.
Additional Information
Cluster upgrade overwrites this because the pf9-kube installs and configures the file on the hosts.