Search code examples
kubernetesgoogle-cloud-platformgoogle-kubernetes-enginekubectl

Why does `kubectl logs` only show the most recent log rows?


I have a Kubernetes pod running on Google Container Engine. It has been running for several days, writing to the log, without any restarts.

Why is the command kubectl logs only showing log rows from today?

Where does this limitation come from and is it based on time or number of log rows?


Solution

  • Logrotate is enabled by default on container engine VMs. You should be able to check conf at below location for docker container logs.

    cat /etc/logrotate.d/docker-containers
    

    So when you run kubectl logs, it streams you from current log file. Past logs are already gzipped and also only N compressed files are available as per logrotate configuration.

    You can check all containers log files at location /var/log/containers also sym linked to /var/lib/docker/containers/$containerId/

    You may also want to refer to documentation https://kubernetes.io/docs/reference/kubectl/generated/kubectl_logs/#options and see if additional options can come to rescue.