How To Rotate Container Logs on The Master and Worker Nodes

Problem

Container logs are utilizing all the disk space on the master and worker nodes.

Environment

  • Platform9 Managed Kubernetes - All Versions

  • Docker

Cause

The docker service is not configured to rotate the container logs.

Resolution

  1. Back up the /etc/docker/daemon.json file on the affected node if present. Add the log rotation config on the node in the file /etc/docker/daemon.json file as shown below.

circle-info

Info

Change the values for max-size and max-file parameter as per your requirement.

$ less /etc/docker/daemon.json
{
   "log-driver": "json-file",
   "log-opts": {
     "max-size": "50m",   
     "max-file": "5"
   }
}
circle-exclamation
  1. Stop the Platform9 Managed Kubernetes stack by executing commands in the below sequence.

  1. Restart the docker service.

  1. Start the Platform9 Managed Kubernetes stack by executing the commands in the below sequence.

  1. Verify the changes took effect on the container by running below command.

Last updated