5

I'm getting a low disk space warning on a server where my microk8s and applications are installed. When I run the microk8s ctr image ls command, multiple images appear for an application. Does the "docker image prune -f" command in Docker have an equivalent in microk8s? Or is there a way possible?

3 Answers3

3

If you want to delete all custom added images from the built-in library, you can do this:

# get all images that start with localhost:32000, output the results into image_ls file
sudo microk8s ctr images ls name~='localhost:32000' | awk {'print $1'} > image_ls 
# loop over file, remove each image
cat image_ls | while read line || [[ -n $line ]];
do
    microk8s ctr images rm $line
done;

Put it into a .sh file and run the script

ahsan
  • 312
  • 1
  • 6
2

You can use:

sudo crictl rmi --prune

to remove unused images (that's because crictl is compatible with containerd).


Instructions:

  1. Install crictl.

  2. Configure crictl, adapting k8s crictl setup docs to microk8s (by using the actual location of containerd.sock valid for microk8s, which is unix:///var/snap/microk8s/common/run/containerd.sock).

  3. Check if crictl is working against microk8s's containerd socket: sudo crictl images

  4. To prune unused images:

sudo crictl rmi --prune
mirekphd
  • 4,799
  • 3
  • 38
  • 59
Yunus Efendi
  • 47
  • 1
  • 1
  • 5
0

A one liner:

sudo microk8s ctr i ls name~='localhost:32000' -q|while read z;do sudo microk8s ctr i rm $z;done

You can remove the filter name~='localhost:32000' or use it to match specific tag you want to clean up, example: name~=':v5.2.0'.

NOTE: If no filter is specified, all local images will be removed

Ron
  • 5,900
  • 2
  • 20
  • 30