Kind kubernetes集群拉取docker镜像失败

p8h8hvxi  于 2023-03-29  发布在  Kubernetes
关注(0)|答案(3)|浏览(273)

我尝试使用KinD作为Minikube的替代品,在本地机器上引导K8S集群。
群集创建成功。
但是当我试图从镜像创建一些pod/部署时,它失败了。

$ kubectl run nginx --image=nginx
$ kubectl run hello --image=hello-world

几分钟后,使用get pods获取失败状态。

$ kubectl get pods
NAME    READY   STATUS             RESTARTS   AGE
hello   0/1     ImagePullBackOff   0          11m
nginx   0/1     ImagePullBackOff   0          22m

恐怕这是中国的另一个全球防火墙问题。

kubectl describe pods/nginx
Name:         nginx
Namespace:    default
Priority:     0
Node:         dev-control-plane/172.19.0.2
Start Time:   Sun, 30 Aug 2020 19:46:06 +0800
Labels:       run=nginx
Annotations:  <none>
Status:       Pending
IP:           10.244.0.5
IPs:
  IP:  10.244.0.5
Containers:
  nginx:
    Container ID:
    Image:          nginx
    Image ID:
    Port:           <none>
    Host Port:      <none>
    State:          Waiting
      Reason:       ErrImagePull
    Ready:          False
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-mgq96 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  default-token-mgq96:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-mgq96
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason     Age                From                        Message
  ----     ------     ----               ----                        -------
  Normal   Scheduled  56m                default-scheduler           Successfully assigned default/nginx to dev-control-plane
  Normal   BackOff    40m                kubelet, dev-control-plane  Back-off pulling image "nginx"
  Warning  Failed     40m                kubelet, dev-control-plane  Error: ImagePullBackOff
  Warning  Failed     13m (x3 over 40m)  kubelet, dev-control-plane  Failed to pull image "nginx": rpc error: code = Unknown desc = failed to pull and unpack image "docker.io/library/nginx:latest": failed to copy: unexpected EOF
  Warning  Failed     13m (x3 over 40m)  kubelet, dev-control-plane  Error: ErrImagePull
  Normal   Pulling    13m (x4 over 56m)  kubelet, dev-control-plane  Pulling image "nginx"

当我进入kindest/node容器时,里面没有docker,不清楚KIND是怎么工作的,原来我理解它是将一个K8S集群部署到一个Docker容器中。

$ docker ps
CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS                       NAMES
a644f8b61314        kindest/node:v1.19.0   "/usr/local/bin/entr…"   About an hour ago   Up About an hour    127.0.0.1:52301->6443/tcp   dev-control-plane

$ docker exec -it  a644f8b61314  /bin/bash
root@dev-control-plane:/# docker -v
bash: docker: command not found

在阅读了Kind文档后,我找不到像Minikube那样设置仓库镜像的选项。
顺便说一句,我正在Windows 10上使用最新的Docker Desktop beta。

4szc88ey

4szc88ey1#

首先使用docker pull nginx在本地系统中拉取映像,然后使用下面的命令将该映像加载到kind集群

kind load docker-image nginx --name kind-cluster-name

Kind使用containerd而不是docker作为运行时,这就是为什么docker没有安装在节点上。
或者,您可以使用crictl工具来拉取和检查kind节点中的图像。

crictl pull nginx
crictl images
2izufjch

2izufjch2#

我遇到了同样的问题,因为我在创建集群之前将http_proxyhttps_proxy导出到本地代理(127.0.0.1),该代理在集群中不可访问。在取消http(s)_proxy并重新创建集群之后,一切正常。

f4t66c6m

f4t66c6m3#

因为其他的答案对我的情况没有帮助:在运行kind create cluster之前,需要设置http(s)_proxy环境变量。只为docker resp. containerd设置环境在这里没有帮助:

export http_proxy=http://...
export https_proxy=http://...

kind create cluster --config ...

相关问题