I have imported some docker images to microk8s image cache for local kubernetes deployment using,
microk8s.ctr -n k8s.io image import <docker_image_name>.tar
how can I remove some of the unwanted images from this cache? Is there any command for that?
Thanks in advance!
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;
Yes, I've used David Castros comment as a base, but since it did not work for Microk8s, I needed to adapt it a bit.
With --help
you can see the that there is a remove option:
> microk8s.ctr -n k8s.io images --help
NAME:
ctr images - manage images
USAGE:
ctr images command [command options] [arguments...]
COMMANDS:
check check that an image has all content available locally
export export an image
import import images
list, ls list images known to containerd
pull pull an image from a remote
push push an image to a remote
remove, rm remove one or more images by reference
label set and clear labels for an image
OPTIONS:
--help, -h show help
So you can see the running containers with:
microk8s.ctr -n k8s.io containers ls
And later remove images with:
microk8s.ctr -n k8s.io images rm "image_ref"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With