狂自私

导航

K8s-V1.22以上版本如何管理docker镜像

K8s1.22以上版本已经不在使用docker作为底层容器管理了,所以K8s创建的pod,使用docker ps -a也看不到任何输出了。取而代之的是crictl。

通过询问ChatGPT,我们极有可能需要搭建一个私有镜像仓库:

 

1、查看K8s拉取的镜像

[root@CentOs8-K8S-node0 ~]# crictl images
IMAGE                                                TAG                 IMAGE ID            SIZE
docker.io/flannel/flannel-cni-plugin                 v1.2.0              a55d1bad692b7       3.88MB
docker.io/flannel/flannel                            v0.24.0             0dc86fe0f22e6       28MB
docker.io/library/mysql                              5.7                 5107333e08a87       138MB
registry.aliyuncs.com/google_containers/kube-proxy   v1.28.2             c120fed2beb84       24.6MB
registry.aliyuncs.com/google_containers/pause        3.9                 e6f1816883972       322kB
[root@CentOs8-K8S-node0 ~]#

 2、报错:

[gyj@CentOs8-K8S-node0 ~]$ crictl images
FATA[0000] validate service connection: validate CRI v1 image API for endpoint "unix:///run/containerd/containerd.sock": rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing: dial unix /run/containerd/containerd.sock: connect: permission denied"

权限不足,使用sudo来运行。

3、报错:

WARN[0000] image connect using default endpoints: [unix:///var/run/dockershim.sock unix:///run/containerd/containerd.sock unix:///run/crio/crio.sock unix:///var/run/cri-dockerd.sock]. As the default settings are now deprecated, you should set the endpoint instead.
ERRO[0000] validate service connection: validate CRI v1 image API for endpoint "unix:///var/run/dockershim.sock": rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing: dial unix /var/run/dockershim.sock: connect: no such file or directory"

解决办法:
crictl config runtime-endpoint unix:///run/containerd/containerd.sock
crictl config image-endpoint unix:///run/containerd/containerd.sock

 4、导入导出crictl中的镜像:

crictl没有提供 save 和 load 命令,所有需要使用 ctr 提供命令来操作:

ctr -n k8s.io image import busybox.tar.gz  #导入
ctr -n k8s.io image export busybox.tar.gz docker.io/library/busybox:latest  #导出

需要注意的是 ctr 是 containerd 自带的工具,有命名空间的概念。Kubernetes 下使用的 containerd 默认命名空间是 k8s.io。所以在导入镜像时需要指定命令空间为 k8s.io,否则使用 crictl images 无法查询到。
参考链接:https://www.jianshu.com/p/0671f094117b
 5、构建镜像
参考 https://blog.csdn.net/tankpanv/article/details/131832952
 

posted on 2023-12-26 10:17  狂自私  阅读(195)  评论(0编辑  收藏  举报