본문 바로가기
IT Knowledge/Kubernetes

Kubernetes Garbage Collection(용량정리)

by Seok. 2025. 3. 20.
반응형

Kubernetes 운영하다보면, 아래와 같이 Node Disk 용량이 많이 차는 경우가 있다.

 

주된 용량의 사용처는

30G.   /var/lib/containerd/io.containerd.content.v1.content

70G.   /var/lib/containerd/io.containerd.snapshotter.v1.overlayfs

 

위의 경로는 Node Containerd에서 사용하는 용량이 많다는 것이고, 나의 경우, 사용하지 않는 컨테이너 이미지가 많이 쌓여서 생기는 현상이었다.

 

용량 관리를 위해

사용하지 않는 이미지를 삭제해주는 것이 좋다.

 

[수동삭제 방법]

# crictl rmi --prune

(--prune 옵션을 주면, 사용하지 않는 이미지만 삭제할 수 있다)

 

[자동삭제 방법]

 

Kubernetes kubeletConfiguration 수정

imageGCHighThresholdPercent : 디스크 사용량이 지정된 임계값을 초과하면, Image Garbage Collection 시작하도록 설정

imageGCLowThresholdPercent : 디스크 사용량이 임계값이하로 떨어지면 가비지 컬렉션을 중지

 

# vi /var/lib/kubelet/config.yaml

 

# journalctl -xeu kubelet


17:03:21.086379    image_gc_manager.go:323] "Disk usage on image filesystem is over the high threshold, trying to free bytes down to the low threshold" usage=80 highThreshold=80 amountToFree=41903259648 lowThreshold=50
...
17:03:21.160109    image_gc_manager.go:400] "Removing image to free bytes" imageID="sha256:88527c8a5667f630151c6755fd0c748d96b690af04304c3b1d3d44" size=111866943
17:03:21.219055    image_gc_manager.go:400] "Removing image to free bytes" imageID="sha256:620d5e2a39df18991f9860078608ab85c8c0a7fd23c770afaa5007b88" size=98718836
17:03:21.340609    image_gc_manager.go:400] "Removing image to free bytes" imageID="sha256:9dbbda55ff5ad08e2550ca9e3d6dd45fbe869b142bcc191c9ccea88e7" size=157385977
17:03:21.418895    image_gc_manager.go:400] "Removing image to free bytes" imageID="sha256:ee13a5352b6b3177ba165a1e78710588d9e5280bc2027ae075215cc0" size=202474350
17:03:21.649857    image_gc_manager.go:400] "Removing image to free bytes" imageID="sha256:b1addf2467b3c959b308469af2312f8c160dd96210ed4bb981f6ba8" size=107805712
17:03:21.974876    image_gc_manager.go:400] "Removing image to free bytes" imageID="sha256:48501593685198eea0230a1253c56a5c5264b2268e83a582fd8e6a4" size=134137997
17:03:22.041360    image_gc_manager.go:400] "Removing image to free bytes" imageID="sha256:6a36c081d22bdb8e76ba73510f59970f91bed37073544f15bf7e9d3c" size=489825506
17:03:22.346688    image_gc_manager.go:400] "Removing image to free bytes" imageID="sha256:0584b370e9509e10f4859a02ab0fda255103f75b3f8c7d410a4e96ed5" size=56732885
17:03:22.602026    image_gc_manager.go:400] "Removing image to free bytes" imageID="sha256:370be99b620ba808f046552fcc03bad16f6dac8ee8ae0f259f608fdceb" size=103452518
...
17:04:18.614968    kubelet.go:1427] "Image garbage collection failed multiple times in a row" err="Failed to garbage collect required amount of images. Attempted to free 41903259648 bytes, but only found 41157887934 bytes eligible to free."

 

자동 삭제된 결과.

/dev/sda4  Mounted on "/" 밑에 공간이 80% > 11% 줄어들면서

기존에 106G 사용하던걸 14G까지 떨어졌다.

반응형

댓글