概述

之前在部署 V1.19.8 的k8s集群时,使用的是docker,现在使用 containerd方式 部署k8s后,并没有docker环境(无法通过docker login命令从本地私服认证),使用 crictl 工具也没有 crictl login 这样的命令,如果直接使用 crictl pull会报错,如下:

[root@k8s-172 ~]# crictl pull nexus3.kevin.com:8870/openjdk:15.0.2-slim-base
FATA[0000] pulling image: rpc error: code = Unknown desc = failed to pull and unpack image "nexus3.kevin.com:8870/openjdk:15.0.2-slim-base": failed to resolve reference "nexus3.kevin.com:8870/openjdk:15.0.2-slim-base": failed to do request: Head https://nexus3.kevin.com:8870/v2/openjdk/manifests/15.0.2-slim-base: http: server gave HTTP response to HTTPS client 
[root@k8s-173 ~]#

配置

只需要在每台节点修改 vim /etc/containerd/config.toml 这个配置文件即可

[plugins]
  [plugins."io.containerd.grpc.v1.cri"]
    [plugins."io.containerd.grpc.v1.cri".cni]
      bin_dir = "/opt/cni/bin"
      conf_dir = "/etc/cni/net.d"
      max_conf_num = 1
      conf_template = ""
    [plugins."io.containerd.grpc.v1.cri".registry]
      [plugins."io.containerd.grpc.v1.cri".registry.mirrors]
        [plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
          endpoint = ["https://registry.cn-hangzhou.aliyuncs.com"]
##################添加部分开始###################
        [plugins."io.containerd.grpc.v1.cri".registry.mirrors."nexus3.kevin.com:8870"]
          endpoint = ["http://nexus3.kevin.com:8870"]
      [plugins."io.containerd.grpc.v1.cri".registry.configs]
        [plugins."io.containerd.grpc.v1.cri".registry.configs."nexus3.kevin.com:8870".tls]
          insecure_skip_verify = true
        [plugins."io.containerd.grpc.v1.cri".registry.configs."nexus3.kevin.com:8870".auth]
          username = "admin"
          password = "admin"
###################添加部分结束##################

重启服务

[root@k8s-172 ~]# systemctl restart containerd.service

测试

[root@k8s-172 ~]# crictl pull nexus3.kevin.com:8870/openjdk:15.0.2-slim-base
Image is up to date for sha256:c7e2b8dc892be191db6cb692224a898bc40c7bd84821ef11230ef616be1d6a73
## 查看镜像列表,openjdk已pull成功
[root@k8s-172 ~]# crictl images
IMAGE                                                            TAG                 IMAGE ID            SIZE
docker.io/kubernetesui/dashboard                                 v2.0.5              fd110d63b15bd       67.7MB
docker.io/kubernetesui/metrics-scraper                           v1.0.6              48d79e554db69       15.1MB
docker.io/library/nginx                                          latest              62d49f9bab67f       53.7MB
docker.io/library/traefik                                        v2.3.6              b52fea93906ad       28.4MB
nexus3.kevin.com:8870/openjdk                                    15.0.2-slim-base    c7e2b8dc892be       227MB
quay.io/coreos/flannel                                           v0.12.0-amd64       4e9f801d2217e       17.1MB
registry.aliyuncs.com/google_containers/pause                    3.2                 80d28bedfe5de       300kB
registry.cn-hangzhou.aliyuncs.com/google_containers/coredns      1.7.0               bfe3a36ebd252       14MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy   v1.20.5             5384b16505072       49.5MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy   v1.20.6             9a1ebfd8124d7       49.5MB
[root@k8s-172 ~]#

注意: crictl 并没有 push 到个人仓库的命令,所以,如果你想要构建镜像发布到私服,docker/podman还是需要的。

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐