如何删除添加到 microk8s 图像缓存中的 docker 图像?

anj*_*nju 5 kubernetes docker-image microk8s

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

microk8s.ctr -n k8s.io image import <docker_image_name>.tar
Run Code Online (Sandbox Code Playgroud)

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

提前致谢!

Mar*_*rco 6

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

# 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;
Run Code Online (Sandbox Code Playgroud)

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


Kam*_*our 6

也可以在一行中完成

microk8s ctr images rm $(microk8s ctr images ls name~='localhost:32000' | awk {'print $1'})
Run Code Online (Sandbox Code Playgroud)


Mat*_*att 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
Run Code Online (Sandbox Code Playgroud)

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

 microk8s.ctr -n k8s.io containers ls
Run Code Online (Sandbox Code Playgroud)

然后删除图像:

 microk8s.ctr -n k8s.io images rm "image_ref"
Run Code Online (Sandbox Code Playgroud)

  • @AdharshManikandan:sudo ctr -n k8s.io 我列出| awk {'print $1'} &gt; image_ls &amp;&amp; for 'cat image_ls' 中的图像;执行 sudo ctr -n k8s.io 我删除 $image; 完毕; (2认同)