本文介绍了创建新部署后,适用于Windows的Docker for Kubernetes pod获得ImagePullBackOff的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功构建了Docker映像并将其运行在Docker群中.当我尝试构建映像并通过Docker Desktop的Kubernetes集群运行它时:

I have successfully built Docker images and ran them in a Docker swarm. When I attempt to build an image and run it with Docker Desktop's Kubernetes cluster:

docker build -t myimage -f myDockerFile .

(上面成功在docker本地注册表中创建了一个映像)

(the above successfully creates an image in the docker local registry)

kubectl run myapp --image=myimage:latest

(据我了解,这与使用kubectl create deploy命令相同)

(as far as I understand, this is the same as using the kubectl create deployment command)

上面的命令成功创建了一个部署,但是当它创建一个pod时,pod的状态始终显示为:

The above command successfully creates a deployment, but when it makes a pod, the pod status always shows:

NAME                                   READY  STATUS            RESTARTS  AGE
myapp-<a random alphanumeric string>   0/1    ImagePullBackoff  0         <age>

我不确定为什么它在提取映像时会遇到麻烦-也许不知道docker本地映像在哪里?

I am not sure why it is having trouble pulling the image - does it maybe not know where the docker local images are?

推荐答案

我遇到了完全相同的问题.归结为imagePullPolicy:

I just had the exact same problem. Boils down to the imagePullPolicy:

PC:~$ kubectl explain deployment.spec.template.spec.containers.imagePullPolicy
KIND:     Deployment
VERSION:  extensions/v1beta1

FIELD:    imagePullPolicy <string>

DESCRIPTION:
     Image pull policy. One of Always, Never, IfNotPresent. Defaults to Always
     if :latest tag is specified, or IfNotPresent otherwise. Cannot be updated.
     More info:
     https://kubernetes.io/docs/concepts/containers/images#updating-images

具体来说,显示以下内容的部分:如果指定了:latest标记,则默认为始终.

Specifically, the part that says: Defaults to Always if :latest tag is specified.

这意味着您创建了本地映像,但是,因为使用了:latest,它将尝试在您配置的任何远程存储库(默认为docker hub)中找到它,而不是使用本地映像.只需将命令更改为:

That means, you created a local image, but, because you use the :latest it will try to find it in whatever remote repository you configured (by default docker hub) rather than using your local. Simply change your command to:

kubectl run myapp --image=myimage:latest --image-pull-policy Never

kubectl run myapp --image=myimage:latest --image-pull-policy IfNotPresent

这篇关于创建新部署后,适用于Windows的Docker for Kubernetes pod获得ImagePullBackOff的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-01 13:31