如何制作microk8s ctr图像修剪

发布于 2025-02-02 17:41:08 字数 141 浏览 7 评论 0 原文

我在安装Microk8和应用程序的服务器上获得了低磁盘空间警告。当我运行Microk8s CTR Image LS命令时,将出现多个用于应用程序的图像。 Docker中的“ Docker Image Prune -f”命令是否在Microk8s中具有等效?还是有可能?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

む无字情书 2025-02-09 17:41:08

如果要删除内置库中的所有自定义添加的图像,则可以这样做:

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

将其放入.sh文件中并运行脚本

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

旧竹 2025-02-09 17:41:08

您可以使用:

sudo crictl rmi -prune

删除未使用的图像(这是因为 crictl containerd )兼容。


说明:

  1. crictl


  2. 配置 crictl ,适应 microk8s (通过使用 containerd.sock的实际位置 microk8s 有效,它是 unix:/ ///var/snap/microk8s/common/run/containerd.sock)。


  3. 检查 crictl 是否正在针对Microk8s的 Containerd 套接字: sudo crictl Images

  4. 修剪未使用的图像:

sudo crictl rmi --prune

You can use:

sudo crictl rmi --prune

to remove unused images (that's because crictl is compatible with containerd).


Instructions:

  1. Install crictl.

  2. Configure crictl, adapting k8s crictl setup docs to microk8s (by using the actual location of containerd.sock valid for microk8s, which is unix:///var/snap/microk8s/common/run/containerd.sock).

  3. Check if crictl is working against microk8s's containerd socket: sudo crictl images

  4. To prune unused images:

sudo crictl rmi --prune
久伴你 2025-02-09 17:41:08

一个衬里:

sudo microk8s ctr i ls name~='localhost:32000' -q|while read z;do sudo microk8s ctr i rm $z;done

您可以删除过滤器 name〜='localhost:32000'或使用它匹配要清理的特定标签,例如: name〜=':v5.2.0 '

注意:如果未指定过滤器,所有本地图像将被删除

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

一杯敬自由 2025-02-09 17:41:08

我建议正确配置kubelet 外部GC。

“您应该避免使用外部垃圾收集工具,因为这些工具可能会破坏kubelet行为并删除应该存在的容器。”

I recommend properly configuring kubelet, the docs recommend against any external GC.

"You should avoid using external garbage collection tools, as these can break the kubelet behavior and remove containers that should exist."

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文