我在安装了我的 microk8s 和应用程序的服务器上收到磁盘空间不足警告。当我运行 microk8s ctr image ls 命令时,一个应用程序会显示多个图像。 Docker 中的“docker image prune -f”命令在 microk8s 中是否有等效命令?或者有什么办法吗?
如果你想从内置库中删除所有自定义添加的图像,你可以这样做:
# 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文件并运行脚本
您可以使用
crictl
修剪未使用的图像,因为 crictl
与 containerd 兼容
crictl
使用这个https://github.com/kubernetes-sigs/cri-tools/blob/edf14e37007994d69f9b8cb3b1483a79b365b8eb/docs/crictl.md#install-crictlcrictl
是否正在使用 microk8s containerd
sudo crictl --runtime-endpoint unix:///var/snap/microk8s/common/run/containerd.sock images
sudo crictl --runtime-endpoint unix:///var/snap/microk8s/common/run/containerd.sock rmi --prune
文档说你也可以使用
CONTAINER_RUNTIME_ENDPOINT
但我不能让它工作。
更新: 您还可以使用配置文件,将以下内容添加到 /etc/crictl.yaml:
runtime-endpoint: unix:///var/snap/microk8s/common/run/containerd.sock
一个班轮:
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'
.
注意:如果没有指定过滤器,将删除所有本地图像