"crictl rmi" removing all the images which are in use

Viewed 6756

I'm trying to remove all unused images with specific name format from Kubernetes cluster like below.

crictl images | grep -E -- 'foo|bar' | awk '{print \$3}' | xargs -n 1 crictl rmi

But this one also deletes all the images with naming "foo" or "bar" even it's in use by container. Tried using "crictl rmi -q" but that deletes multiple other images which are not in the filter above.

1 Answers

Probably you want to run

crictl rmi --prune

You need a rather current crictl for that. From the help:

$ crictl rmi --help
NAME:
   crictl rmi - Remove one or more images

USAGE:
   crictl rmi [command options] IMAGE-ID [IMAGE-ID...]

OPTIONS:
   --all, -a    Remove all images (default: false)
   --prune, -q  Remove all unused images (default: false)
   --help, -h   show help (default: false)
Related