Docker for Windows Kubernetes pod gets ImagePullBackOff after creating a new deployment

烈酒焚心 提交于 2021-01-02 08:31:56

问题


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 .

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

kubectl run myapp --image=myimage:latest

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

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>

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


回答1:


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

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

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

or

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



回答2:


You didn't specify where myimage:latest is hosted, but essentially ImagePullBackoff means that I cannot pull the image because either:

  • You don't have networking setup in your Docker VM that can get to your Docker registry (Docker Hub?)
  • myimage:latest doesn't exist in your registry or is misspelled.
  • myimage:latest requires credentials (you are pulling from a private registry). You can take a look at this to configure container credentials in a Pod.



回答3:


I had this same ImagePullBack error while running a pod deployment with a YAML file, also on Docker Desktop.

For anyone else that finds this via Google (like I did), the imagePullPolicy that Lucas mentions above can also be set in the deployment yaml file. See the spec.templage.spec.containers.imagePullPolicy in the yaml snippet below (3 lines from the bottom).

I added that and my app deployed successfully into my local kube cluser, using the kubectl yaml deploy command: kubectl apply -f .\Deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-app-deployment
  labels:
    app: web-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web-app
  template:
    metadata:
      labels:
        app: web-app
    spec:
      containers:
      - name: web-app
        image: node-web-app:latest
        imagePullPolicy: Never
        ports:
        - containerPort: 3000


来源:https://stackoverflow.com/questions/53822385/docker-for-windows-kubernetes-pod-gets-imagepullbackoff-after-creating-a-new-dep

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!