Kubernetes – Prune Old Container Images and Set Image Threshold for K3s


K3s kubelet args

The k3s binary allows for supplying vanilla Kubernetes args using the --kubelet-arg= switch. Two of these are useful in tuning Kubernetes built in garbage collection for pruning old unused container images. Much link Dockers docker image prune.

One of

If you want to clear old images just once to free up some storage, you can run

sudo k3s crictl rmi --prune

Tuning K3s Built in Garbage Collection

Both of the following options can be added ass arguments k3s server.

--kubelet-arg=image-gc-high-threshold=30 This option sets the high threshold for image garbage collection as 30%. It tells the kubelet at what disk usage percentage to start deleting old images. When the disk usage reaches this threshold, the kubelet begins to delete unused images until the disk usage falls below the low threshold. This is a proactive measure to prevent the disk from filling up completely, which could cause issues with the cluster.

--kubelet-arg=image-gc-low-threshold=25 This option sets the low threshold for image garbage collection as 25%. It specifies the target disk usage percentage to achieve after cleaning up unused images. Once the kubelet starts deleting images because the high threshold was reached, it continues to delete old images until the disk usage falls below this low threshold.

Keep it clean

Leave a Reply

Your email address will not be published. Required fields are marked *