You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature request: container log rotate and size limit #3351
We migrated our cluster from docker to containerd. We are running k8s + containerd + overlayfs now. We used to set the container log size limitation by following configuration of docker:
containerd does not do anything with logs. It provides the direct IO to clients (CRI, docker, etc) and they can rotate. We shouldn't have any rotation or the notion of log drivers in the containerd core.
Kubelet works abnormal sometimes, and log rotate not work, but container is still running
Can you provide more context? We should fix it.
Container writes lots of logs and kubelet just rotate the log every 10s. We can saw many logs not rotated in some cases and disk full.
We can make the rotate frequency configurable. However, I think 10s is already very frequent. I think most log rotate solution has this limitation, e.g. logrotate is also periodically invoked with cron. Doesn't Docker log rotate have similar problem? If not, how does Docker solve the problem?
@crosbymichael We used to use docker to do log rotate and overlayfs quota limitation. But we move from docker to containerd, then these two features missed. These two feature is very important feature for user who want to use containerd. If there is no plan to add such feature to containerd. We should have a way to implemented these two features.
@wenlxie For log rotate, we should improve kubelet log rotate to meet your requirement. I heard some issues about kubelet log rotate in KubeCon CN. Can you list those issues? Let's try to solve them.
For overlayfs quota limitation, I think we can try to add the support into containerd or the cri plugin first.
We can make the rotate frequency configurable. However, I think 10s is already very frequent. I think most log rotate solution has this limitation, e.g. logrotate is also periodically invoked with cron. Doesn't Docker log rotate have similar problem? If not, how does Docker solve the problem?
Docker checks the logs number and size before writes log to files.
Issues we met for log rotate:
Log rotate only check running versions of logs, but not care about previous logs.
If a container keeps running and crash, then there will be lots of logs not cleaned.
This is the logs from one of the nodes we didn't fixed this issue.
We met issues when the logs not rotated and have a large file there, not found the root cause yet. We set the log max size to be 10M, and you can see there are logs more than 200M.
-bash-4.2# ls -lah
total 15G
drwxr-xr-x 2 root root 8.0K May 28 18:14 .
drwxr-xr-x 7 root root 77 May 23 12:10 ..
-rw-r--r-- 1 root root 4.4M May 28 12:06 10.log.20190528-120628.gz
-rw-r----- 1 root root 273M May 28 12:06 10.log.20190528-120639
-rw-r--r-- 1 root root 12M May 28 12:12 11.log.20190528-121201.gz
-rw-r--r-- 1 root root 7.2M May 28 12:17 12.log.20190528-121735.gz
-rw-r----- 1 root root 267M May 28 12:17 12.log.20190528-121747
-rw-r--r-- 1 root root 1.6M May 28 12:23 13.log.20190528-122300.gz
-rw-r--r-- 1 root root 11M May 28 12:23 13.log.20190528-122310.gz
-rw-r--r-- 1 root root 2.2M May 28 12:28 14.log.20190528-122834.gz
-rw-r----- 1 root root 296M May 28 12:28 14.log.20190528-122845
-rw-r--r-- 1 root root 1.4M May 28 12:34 15.log.20190528-123407.gz
-rw-r--r-- 1 root root 12M May 28 12:34 15.log.20190528-123417.gz
-rw-r--r-- 1 root root 1.1M May 28 12:39 16.log.20190528-123942.gz
-rw-r--r-- 1 root root 11M May 28 12:40 16.log.20190528-123952.gz
-rw-r--r-- 1 root root 1.5M May 28 12:45 17.log.20190528-124507.gz
-rw-r--r-- 1 root root 12M May 28 12:45 17.log.20190528-124517.gz
-rw-r--r-- 1 root root 11M May 28 12:51 18.log.20190528-125051.gz
-rw-r----- 1 root root 224M May 28 12:51 18.log.20190528-125103
-rw-r--r-- 1 root root 6.4M May 28 12:56 19.log.20190528-125615.gz
-rw-r----- 1 root root 251M May 28 12:56 19.log.20190528-125626
-rw-r--r-- 1 root root 5.0M May 28 13:01 20.log.20190528-130148.gz
-rw-r----- 1 root root 276M May 28 13:01 20.log.20190528-130159
-rw-r--r-- 1 root root 2.4M May 28 13:07 21.log.20190528-130712.gz
-rw-r--r-- 1 root root 11M May 28 13:07 21.log.20190528-130722.gz
-rw-r--r-- 1 root root 9.2M May 28 13:13 22.log.20190528-131256.gz
-rw-r----- 1 root root 248M May 28 13:13 22.log.20190528-131308
-rw-r--r-- 1 root root 4.7M May 28 13:18 23.log.20190528-131821.gz
-rw-r----- 1 root root 271M May 28 13:18 23.log.20190528-131832
-rw-r--r-- 1 root root 4.2M May 28 13:24 24.log.20190528-132355.gz
-rw-r----- 1 root root 279M May 28 13:24 24.log.20190528-132406
-rw-r--r-- 1 root root 718K May 28 13:29 25.log.20190528-132918.gz
-rw-r--r-- 1 root root 12M May 28 13:29 25.log.20190528-132928.gz
-rw-r--r-- 1 root root 8.3M May 28 13:35 26.log.20190528-133453.gz
-rw-r----- 1 root root 262M May 28 13:35 26.log.20190528-133505
-rw-r--r-- 1 root root 9.6M May 28 13:40 27.log.20190528-134017.gz
-rw-r----- 1 root root 245M May 28 13:40 27.log.20190528-134029
-rw-r--r-- 1 root root 9.4M May 28 13:46 28.log.20190528-134551.gz
-rw-r----- 1 root root 247M May 28 13:46 28.log.20190528-134603
-rw-r--r-- 1 root root 9.7M May 28 13:51 29.log.20190528-135114.gz
-rw-r----- 1 root root 240M May 28 13:51 29.log.20190528-135127
-rw-r--r-- 1 root root 589K May 28 11:44 2.log.20190528-113154.gz
-rw-r--r-- 1 root root 590K May 28 11:47 2.log.20190528-114435.gz
-rw-r--r-- 1 root root 9.7M May 28 11:47 2.log.20190528-114746.gz
-rw-r----- 1 root root 244M May 28 11:47 2.log.20190528-114758
-rw-r--r-- 1 root root 4.1M May 28 13:56 30.log.20190528-135638.gz
-rw-r----- 1 root root 263M May 28 13:56 30.log.20190528-135649
-rw-r--r-- 1 root root 905K May 28 14:02 31.log.20190528-140200.gz
-rw-r--r-- 1 root root 11M May 28 14:02 31.log.20190528-140210.gz
-rw-r--r-- 1 root root 2.6M May 28 14:07 32.log.20190528-140735.gz
-rw-r----- 1 root root 269M May 28 14:07 32.log.20190528-140745
-rw-r--r-- 1 root root 10M May 28 14:13 33.log.20190528-141308.gz
-rw-r----- 1 root root 238M May 28 14:13 33.log.20190528-141320
-rw-r--r-- 1 root root 5.5M May 28 14:18 34.log.20190528-141831.gz
-rw-r----- 1 root root 272M May 28 14:18 34.log.20190528-141842
-rw-r--r-- 1 root root 6.2M May 28 14:24 35.log.20190528-142406.gz
-rw-r----- 1 root root 282M May 28 14:24 35.log.20190528-142417
-rw-r--r-- 1 root root 9.2M May 28 14:29 36.log.20190528-142941.gz
-rw-r----- 1 root root 250M May 28 14:29 36.log.20190528-142952
-rw-r--r-- 1 root root 3.5M May 28 14:34 37.log.20190528-143445.gz
-rw-r--r-- 1 root root 12M May 28 14:35 37.log.20190528-143456.gz
-rw-r--r-- 1 root root 9.5M May 28 14:35 38.log.20190528-143531.gz
-rw-r--r-- 1 root root 11M May 28 14:36 39.log.20190528-143625.gz
-rw-r--r-- 1 root root 6.8M May 28 11:48 3.log.20190528-114808.gz
-rw-r----- 1 root root 247M May 28 11:48 3.log.20190528-114820
-rw-r--r-- 1 root root 5.0M May 28 14:37 40.log.20190528-143730.gz
-rw-r----- 1 root root 307M May 28 14:37 40.log.20190528-143743
-rw-r--r-- 1 root root 2.3M May 28 14:39 41.log.20190528-143913.gz
-rw-r----- 1 root root 301M May 28 14:39 41.log.20190528-143924
-rw-r--r-- 1 root root 535K May 28 14:42 42.log.20190528-144215.gz
-rw-r--r-- 1 root root 12M May 28 14:42 42.log.20190528-144225.gz
-rw-r--r-- 1 root root 550K May 28 14:48 43.log.20190528-144749.gz
-rw-r--r-- 1 root root 11M May 28 14:48 43.log.20190528-144800.gz
-rw-r----- 1 root root 202M May 28 14:48 43.log.20190528-144812
-rw-r--r-- 1 root root 2.1M May 28 14:53 44.log.20190528-145325.gz
-rw-r----- 1 root root 328M May 28 14:53 44.log.20190528-145337
-rw-r--r-- 1 root root 1.3M May 28 14:58 45.log.20190528-145848.gz
-rw-r----- 1 root root 286M May 28 14:58 45.log.20190528-145858
-rw-r--r-- 1 root root 6.9M May 28 15:04 46.log.20190528-150420.gz
-rw-r----- 1 root root 278M May 28 15:04 46.log.20190528-150431
-rw-r--r-- 1 root root 9.9M May 28 15:10 47.log.20190528-150953.gz
-rw-r----- 1 root root 228M May 28 15:10 47.log.20190528-151005
-rw-r--r-- 1 root root 8.3M May 28 15:15 48.log.20190528-151517.gz
-rw-r----- 1 root root 263M May 28 15:15 48.log.20190528-151529
-rw-r--r-- 1 root root 7.4M May 28 15:21 49.log.20190528-152050.gz
-rw-r----- 1 root root 267M May 28 15:21 49.log.20190528-152102
-rw-r--r-- 1 root root 4.4M May 28 11:48 4.log.20190528-114842.gz
-rw-r----- 1 root root 320M May 28 11:48 4.log.20190528-114855
-rw-r--r-- 1 root root 6.7M May 28 15:26 50.log.20190528-152614.gz
-rw-r----- 1 root root 262M May 28 15:26 50.log.20190528-152626
-rw-r--r-- 1 root root 3.5M May 28 15:31 51.log.20190528-153148.gz
-rw-r----- 1 root root 281M May 28 15:31 51.log.20190528-153159
-rw-r--r-- 1 root root 8.9M May 28 15:37 52.log.20190528-153731.gz
-rw-r--r-- 1 root root 9.5M May 28 15:43 53.log.20190528-154257.gz
-rw-r----- 1 root root 245M May 28 15:43 53.log.20190528-154309
-rw-r--r-- 1 root root 4.2M May 28 15:48 54.log.20190528-154821.gz
-rw-r----- 1 root root 284M May 28 15:48 54.log.20190528-154832
-rw-r----- 1 root root 215M May 28 15:54 55.log.20190528-155402
-rw-r--r-- 1 root root 8.8M May 28 15:59 56.log.20190528-155925.gz
-rw-r----- 1 root root 243M May 28 15:59 56.log.20190528-155937
-rw-r--r-- 1 root root 11M May 28 16:05 57.log.20190528-160459.gz
-rw-r----- 1 root root 232M May 28 16:05 57.log.20190528-160511
-rw-r--r-- 1 root root 1.4M May 28 16:10 58.log.20190528-161022.gz
-rw-r----- 1 root root 296M May 28 16:10 58.log.20190528-161033
-rw-r--r-- 1 root root 4.0M May 28 16:16 59.log.20190528-161555.gz
-rw-r----- 1 root root 266M May 28 16:16 59.log.20190528-161606
-rw-r--r-- 1 root root 6.1M May 28 11:49 5.log.20190528-114936.gz
-rw-r----- 1 root root 306M May 28 11:49 5.log.20190528-114949
-rw-r--r-- 1 root root 8.0M May 28 16:21 60.log.20190528-162128.gz
-rw-r----- 1 root root 265M May 28 16:21 60.log.20190528-162142
-rw-r--r-- 1 root root 1.4M May 28 16:27 61.log.20190528-162652.gz
-rw-r--r-- 1 root root 12M May 28 16:27 61.log.20190528-162703.gz
-rw-r--r-- 1 root root 7.8M May 28 16:32 62.log.20190528-163228.gz
-rw-r----- 1 root root 263M May 28 16:32 62.log.20190528-163240
-rw-r--r-- 1 root root 5.3M May 28 16:38 63.log.20190528-163751.gz
-rw-r----- 1 root root 281M May 28 16:38 63.log.20190528-163802
-rw-r--r-- 1 root root 1.7M May 28 16:43 64.log.20190528-164324.gz
-rw-r--r-- 1 root root 12M May 28 16:43 64.log.20190528-164334.gz
-rw-r--r-- 1 root root 1.6M May 28 16:48 65.log.20190528-164849.gz
-rw-r----- 1 root root 280M May 28 16:48 65.log.20190528-164859
-rw-r--r-- 1 root root 11M May 28 16:54 66.log.20190528-165430.gz
-rw-r--r-- 1 root root 4.7M May 28 17:00 67.log.20190528-165954.gz
-rw-r----- 1 root root 277M May 28 17:00 67.log.20190528-170005
-rw-r--r-- 1 root root 957K May 28 17:05 68.log.20190528-170516.gz
-rw-r--r-- 1 root root 12M May 28 17:05 68.log.20190528-170526.gz
-rw-r--r-- 1 root root 893K May 28 17:11 69.log.20190528-171051.gz
-rw-r--r-- 1 root root 11M May 28 17:11 69.log.20190528-171101.gz
-rw-r--r-- 1 root root 7.2M May 28 11:50 6.log.20190528-115041.gz
-rw-r----- 1 root root 265M May 28 11:50 6.log.20190528-115053
-rw-r--r-- 1 root root 1.6M May 28 17:16 70.log.20190528-171625.gz
-rw-r--r-- 1 root root 12M May 28 17:16 70.log.20190528-171636.gz
-rw-r--r-- 1 root root 622K May 28 17:22 71.log.20190528-172151.gz
-rw-r--r-- 1 root root 11M May 28 17:22 71.log.20190528-172201.gz
-rw-r--r-- 1 root root 11M May 28 17:27 72.log.20190528-172734.gz
-rw-r--r-- 1 root root 3.0M May 28 17:33 73.log.20190528-173257.gz
-rw-r--r-- 1 root root 12M May 28 17:33 73.log.20190528-173308.gz
-rw-r--r-- 1 root root 4.5M May 28 17:38 74.log.20190528-173834.gz
-rw-r----- 1 root root 275M May 28 17:38 74.log.20190528-173845
-rw-r--r-- 1 root root 9.4M May 28 17:44 75.log.20190528-174408.gz
-rw-r----- 1 root root 245M May 28 17:44 75.log.20190528-174420
-rw-r--r-- 1 root root 3.7M May 28 17:49 76.log.20190528-174933.gz
-rw-r----- 1 root root 255M May 28 17:49 76.log.20190528-174946
-rw-r--r-- 1 root root 8.3M May 28 11:52 7.log.20190528-115225.gz
-rw-r----- 1 root root 236M May 28 11:52 7.log.20190528-115237
-rw-r----- 1 root root 15M May 28 18:14 84.log
-rw-r--r-- 1 root root 7.6M May 28 11:55 8.log.20190528-115529.gz
-rw-r----- 1 root root 260M May 28 11:55 8.log.20190528-115541
-rw-r--r-- 1 root root 7.6M May 28 12:01 9.log.20190528-120103.gz
-rw-r----- 1 root root 257M May 28 12:01 9.log.20190528-120115
I'm going to close this. There is zero code in containerd that handles logs at all. @Random-Liu said this is more of a kubelet issue so it would be better served to have an issue like this on the kube side.
For future searches,
kubelet has --container-log-max-files and --container-log-max-size implemented by Random-Liu (kubernetes/kubernetes#59898) , so logrotation should work pretty well. At least for me, the defaults were fine per my testing (5 files, max 10Mi each).
I haven't found something for json-file in kubelet so far. I'm having a look.
--container-log-max-files int32
| <Warning: Beta feature> Set the maximum number of container log files that can be present for a container. The number must be ≥ 2. This flag can only be used with --container-runtime=remote. (default 5) (DEPRECATED: This parameter should be set via the config file specified by the Kubelet's --config flag. See https://kubernetes.io/docs/tasks/administer-cluster/kubelet-config-file/ for more information.)
--container-log-max-size string
| <Warning: Beta feature> Set the maximum size (e.g. 10Mi) of container log file before it is rotated. This flag can only be used with --container-runtime=remote. (default "10Mi") (DEPRECATED: This parameter should be set via the config file specified by the Kubelet's --config flag. See https://kubernetes.io/docs/tasks/administer-cluster/kubelet-config-file/ for more information.)
Reacted by Eugene Klimov, W.T. Chang, Chenglong Hu, Stephano Zanzin Ferreira, Furkan Türkal, Li Xiaopeng, Zhēn Xuānxīn, llussy and Andrea Vouk
Is it possible to introduce some basic (or fallback) mechanism in containerd to prevent the logs increasing without limit when the kubelet is not working?
Activity
crosbymichael commentedon Jun 17, 2019
containerd does not do anything with logs. It provides the direct IO to clients (CRI, docker, etc) and they can rotate. We shouldn't have any rotation or the notion of log drivers in the containerd core.
Random-Liu commentedon Jun 21, 2019
@wenlxie Kubelet should handle container log rotate. If it doesn't meet the requirement or has any issue, we should fix it.
Random-Liu commentedon Jun 21, 2019
Can you provide more context? We should fix it.
We can make the rotate frequency configurable. However, I think 10s is already very frequent. I think most log rotate solution has this limitation, e.g. logrotate is also periodically invoked with cron. Doesn't Docker log rotate have similar problem? If not, how does Docker solve the problem?
wenlxie commentedon Jul 18, 2019
@crosbymichael We used to use docker to do log rotate and overlayfs quota limitation. But we move from docker to containerd, then these two features missed. These two feature is very important feature for user who want to use containerd. If there is no plan to add such feature to containerd. We should have a way to implemented these two features.
Random-Liu commentedon Jul 23, 2019
@wenlxie For log rotate, we should improve kubelet log rotate to meet your requirement. I heard some issues about kubelet log rotate in KubeCon CN. Can you list those issues? Let's try to solve them.
For overlayfs quota limitation, I think we can try to add the support into containerd or the cri plugin first.
wenlxie commentedon Aug 2, 2019
@Random-Liu Sorry for miss the message.
Issues we met for log rotate:
If a container keeps running and crash, then there will be lots of logs not cleaned.
This is the logs from one of the nodes we didn't fixed this issue.
vsxen commentedon Sep 6, 2019
/watch
strainovic commentedon Oct 1, 2019
Any update on this issue?
Thanks!
wenlxie commentedon Oct 8, 2019
kubernetes/kubernetes#83608
vishiy commentedon Jan 8, 2020
/watch
crosbymichael commentedon Jan 8, 2020
I'm going to close this. There is zero code in containerd that handles logs at all. @Random-Liu said this is more of a kubelet issue so it would be better served to have an issue like this on the kube side.
strigazi commentedon May 29, 2020
For future searches,
kubelet has
--container-log-max-filesand--container-log-max-sizeimplemented by Random-Liu (kubernetes/kubernetes#59898) , so logrotation should work pretty well. At least for me, the defaults were fine per my testing (5 files, max 10Mi each).I haven't found something for json-file in kubelet so far. I'm having a look.
ydcool commentedon Mar 13, 2021
Is it possible to introduce some basic (or fallback) mechanism in containerd to prevent the logs increasing without limit when the kubelet is not working?