I have a problem about docker log setting and wonder if anyone here could help me. my docker generates a lot of logs, so I set up a rolling update for it, the settings are as follows:
"log-driver": "json-file",
"log-level": "warn",
"log-opts": {
"max-file": "10",
"max-size": "100m"
},
In this way, its log collection will be as follows:
and when I use kubectl logs
, it only read the latest file, which means that at some time, when the log file is just 100M, the latest file will be empty. I wonder if I have a way to read the latest 100M log every time, rather than the latest file. Or how to configure it? Docker can put the latest 100m log in the latest file.
Thanks a lot~
According to the K8S Documentation what you describe is standard behavior and can't be modified:
Note: Currently, if some external system has performed the rotation, only the contents of the latest log file will be available through kubectl logs. E.g. if there’s a 10MB file, logrotate performs the rotation and there are two files, one 10MB in size and one empty, kubectl logs will return an empty response.
I recommend introducing log aggregation to your cluster with a daemon set, e.g. Fluentd with ElasticSearch and Kibana.