【问题标题】:Unable to pull image for deployment creation无法为部署创建拉取映像
【发布时间】:2021-02-07 00:29:19
【问题描述】:

我正在尝试使用以下文件设置 kubernetes pod。 该镜像只是来自 Docker HUB 的基本 hello-world 镜像。

但我不断收到错误。

通过以下命令创建部署

kubectl apply -f config.yaml

没有错误,并说部署已创建。 但是几秒钟后,当我尝试通过以下命令查看 pod 时,我收到了这些错误。

kubectl get pod

输出

some-deployment-857fb6d98b-jzwhq   0/1     ImagePullBackOff   0         
some-deployment-857fb6d98b-ethfs   0/1     ImagePullBackOff   0          
some-deployment-857fb6d98b-w8hgt   0/1     ImagePullBackOff   0  

    

一段时间后,当我运行相同的 get pod 命令时,我得到了这些。

some-deployment-6f88c9fd89-65c47   0/1     CrashLoopBackOff   8          
some-deployment-84d66585d4-k52ns   0/1     CrashLoopBackOff   9          
some-deployment-857fb6d98b-jzwhq   0/1     ErrImagePull       0          
some-deployment-857fb6d98b-w8hgt   0/1     ErrImagePull       0  

    

我只是换了一张图片,看看是不是这张图片有问题。
它一直在变化。为什么我现在有 4 个 pod?

some-deployment-6f88c9fd89-65c47   0/1     Completed          8          
some-deployment-84d66585d4-k52ns   0/1     CrashLoopBackOff   8          
some-deployment-857fb6d98b-jzwhq   0/1     ImagePullBackOff   0          
some-deployment-857fb6d98b-w8hgt   0/1     ImagePullBackOff   0 

     

过了一会儿。

some-deployment-6f88c9fd89-65c47   0/1     CrashLoopBackOff   8          
some-deployment-84d66585d4-k52ns   0/1     CrashLoopBackOff   9          
some-deployment-857fb6d98b-jzwhq   0/1     ImagePullBackOff   0          
some-deployment-857fb6d98b-w8hgt   0/1     ImagePullBackOff   0  

    

问题似乎与图像拉动有关。就我而言,该图像来自公共 Docker HUB。
是什么导致了图片拉取问题?

这是正在使用的文件。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: networkchuckcoffee-deployment
  labels:
    app: nccoffee
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nccoffee
  template:
    metadata:
      labels:
        app: nccoffee
    spec:
      containers:
      - name: nccoffee
        image: hello-world # initially attempted this image which is also public on DockerHUB -> thenetworkchuck/nccoffee 
        imagePullPolicy: Always
        ports:
        - containerPort: 80

Pod 日志。所有 pod 的相同消息:

使用的命令:

kubectl logs some-deployment-857fb6d98b-w8hgt

--

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

描述日志:(这里即使有敏感数据也不关心,之后会删除这个部署)

Name:         some-deployment-857fb6d98b-jzwhq
Namespace:    default
Priority:     0
Node:         app-pool-8nid8/10.106.0.5
Start Time:   Sat, 06 Feb 2021 15:45:38 +0000
Labels:       app=nccoffee
              pod-template-hash=857fb6d98b
Annotations:  <none>
Status:       Running
IP:           10.244.1.96
IPs:
  IP:           10.244.1.96
Controlled By:  ReplicaSet/some-deployment-857fb6d98b
Containers:
  nccoffee:
    Container ID:   containerd://beb3b0ac0cd63abc1821e259c0fe24b8d8170bee68d50bffc5590c9154f07ead
    Image:          hello-world
    Image ID:       docker.io/library/hello-world@sha256:31b9c7d48790f0d8c50ab433d9c3b7e17666d6993084c002c2ff1ca09b96391d
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Sat, 06 Feb 2021 15:56:40 +0000
      Finished:     Sat, 06 Feb 2021 15:56:40 +0000
    Ready:          False
    Restart Count:  7
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-n4n95 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  default-token-n4n95:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-n4n95
    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  13m                  default-scheduler  Successfully assigned default/some-deployment-857fb6d98b-jzwhq to app-pool-8nid8
  Normal   Pulled     13m                  kubelet            Successfully pulled image "hello-world" in 802.715724ms
  Normal   Pulled     13m                  kubelet            Successfully pulled image "hello-world" in 766.964136ms
  Normal   Pulled     12m                  kubelet            Successfully pulled image "hello-world" in 790.211436ms
  Normal   Created    12m (x4 over 13m)    kubelet            Created container nccoffee
  Normal   Pulled     12m                  kubelet            Successfully pulled image "hello-world" in 794.431351ms
  Normal   Started    12m (x4 over 13m)    kubelet            Started container nccoffee
  Normal   Pulling    11m (x5 over 13m)    kubelet            Pulling image "hello-world"
  Normal   Pulled     11m                  kubelet            Successfully pulled image "hello-world" in 807.455498ms
  Warning  BackOff    3m1s (x47 over 13m)  kubelet            Back-off restarting failed container

【问题讨论】:

  • 您是否检查过您没有达到 dockerhub pull 限制(从内存 100pull/6h 作为匿名用户)?如果您使用单个传出 IP 从企业网络操作集群,这可能会很快发生。
  • 运行kubectl logs时Kubernetes会发出什么日志
  • @Zeitounator 从本地网络提取,现在只运行了两次这个文件。因此猜测完成 6 图像拉 * hello-world 图像非常小。
  • 大小无关紧要(我说的是图像;))只有数字。按照@MargachChris 的建议查看日志应该可以提供更多线索。
  • @MargachChris 在上面添加了其中一个处于 crashLoopBackOff 状态的 pod 的日志。所有 pod 日志都输出相同的消息。

标签: docker kubernetes


【解决方案1】:

CrashLoopBackoffhello-world 图像的完全正常状态。它旨在打印您在日志中看到的消息,然后退出。它正在做它被设计做的事情。

Kubernetes 部署期望拥有可以保持运行的容器。所以当容器退出时,会自动重启。如果容器一启动就一直退出,则假定它正在崩溃,因此我们得到CrashLoopBackoff。你需要一个不会退出的容器; hello-world不是吗。

正如其他人所提到的,thenetworkchuck/nccoffee 的问题很可能是您已经达到了 DockerHub 的每日拉取限制。

最后,您有四个部署的原因是您没有删除失败的部署;部署将一直运行直到被删除。 ImagePullBackoff 很可能是 nccoffee 图像,而 CrashLoopBackoff 很可能是 hello-world 图像。

kubectl list deployments 会显示你有什么,然后你可以使用kubectl delete deployment &lt;deployment name&gt;
或者,kubectl delete -f &lt;file.yaml&gt; 将删除您使用kubectl apply -f &lt;file.yaml&gt;(或kubectl create -f ...)创建的内容

【讨论】:

  • 欣赏这个答案中的细节。无疑解开了我的疑惑。这与上面的 cmets 一起触发了寻找问题的正确位置。由于某种原因,thenetworkchuck/nccoffee 图像无法使用默认 :latest 标签。添加它的特定标签成功拉取图像。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-10-12
  • 1970-01-01
  • 2017-09-22
  • 2021-08-26
  • 2019-10-21
  • 2023-03-17
  • 2022-12-11
相关资源
最近更新 更多