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 Answers
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

- 312
- 1
- 6
You can use:
sudo crictl rmi --prune
to remove unused images (that's because crictl
is compatible with containerd
).
Instructions:
Install
crictl
.Configure
crictl
, adapting k8s crictl setup docs tomicrok8s
(by using the actual location ofcontainerd.sock
valid formicrok8s
, which isunix:///var/snap/microk8s/common/run/containerd.sock
).Check if
crictl
is working against microk8s'scontainerd
socket:sudo crictl images
To prune unused images:
sudo crictl rmi --prune

- 4,799
- 3
- 38
- 59

- 47
- 1
- 1
- 5
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

- 5,900
- 2
- 20
- 30