5

我已经将一些 docker 图像导入到 microk8s 图像缓存中,用于本地 kubernetes 部署,使用,

microk8s.ctr -n k8s.io image import <docker_image_name>.tar

如何从此缓存中删除一些不需要的图像?有什么命令吗?

提前致谢!

4

2 回答 2

8

如果要从内置库中删除所有自定义添加的图像,可以执行以下操作:

# 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;

是的,我使用了 David Castros 评论作为基础,但由于它不适用于 Microk8s,我需要对其进行一些调整。

于 2021-01-18T09:03:02.900 回答
5

--help您可以看到有一个删除选项:

> 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

所以你可以看到正在运行的容器:

 microk8s.ctr -n k8s.io containers ls

稍后删除图像:

 microk8s.ctr -n k8s.io images rm "image_ref"
于 2019-11-15T07:14:27.460 回答