Search code examples
kubernetes

is it possible to shrink the spaces of io.containerd.snapshotter.v1.overlayfs folder in kubernetes


Today I found the host kubernetes (v1.21.3) folder io.containerd.snapshotter.v1.overlayfs takes too much spaces:

[root@k8smasterone kubernetes.io~nfs]# pwd
/var/lib/kubelet/pods/8aafe99f-53c1-4bec-8cb8-abd09af1448f/volumes/kubernetes.io~nfs
[root@k8smasterone kubernetes.io~nfs]# duc ls -Fg /var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/
 13.5G snapshots/   [++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++]
  2.2M metadata.db  [

It takes 13.5GB of disk spaces. is it possible to shrink this folder?


Solution

  • The directory /var/lib/containerd/io.containerd.snapshotter.v1.overlayfs is where the various container and image layers are persisted by containerd. These layers are downloaded based on the containers running on the node. If we start running out of space, the kubelet has the ability to garbage collected unused images - which will reduce the size of this directory. The customer also has the ability to configure the size of the boot disk for the node-pools if needed.

    It is expected that this would grow from the time a node is created. However when the node disk usage is above 85% then garbage collection will attempt to identify images that can be removed. It may not be able to remove images though if they are currently in use by an existing container running on the node or they have been recently pulled.

    If you want to remove unused container images with just containerd, you can use the below command:

    $ crictl rmi --prune

    Also you can use the $ docker image prune command which allows you to clean up unused images. By default, docker image prune only cleans up dangling images. A dangling image is one that is not tagged and is not referenced by any container.

    To remove all images which are not used by existing containers, use the -a flag:

    $ docker image prune -a