Skip to content

How to set container log rotation with RKE2

Article Number: 000021045

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. 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.