Skip to content

How to set container log rotation with RKE2

This document (000021045) is provided subject to the disclaimer at the end of this document.

Environment

Container Log rotation with RKE2

Situation

In a Kubernetes cluster running an alternative container runtime, such as containerd, instead of Docker, the kubelet manages container logs. The kubelet default values in relation to log rotation can be found in the upstream kubelet | Kubernetes documentation,-%2D%2Dcontainer%2Druntime%20string). These values can be adjusted by adding options to the kubelet process.

Resolution

Two kubelet options need to be added to RKE2 config file, /etc/rancher/rke2/config.yaml

kubelet-arg:
  - "container-log-max-files=5"
  - "container-log-max-size=10Mi"

Note please adjust the values to suit your needs, for demonstration purposes the above commands used 5 log files of 10MB, allowing for 50MB of total space to be retained per container.

Additional Information

Here is a reference to K3s (which have a similar way to see using CLIt) for setting through binary command.( RKE2 CLI example page)

Disclaimer

This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented "AS IS" WITHOUT WARRANTY OF ANY KIND.