Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 413
JakeJ Avatar asked Dec 17 '18 20:12

JakeJ


People also ask

How do I fix ImagePullBackOff in Kubernetes?

To resolve it, double check the pod specification and ensure that the repository and image are specified correctly. If this still doesn't work, there may be a network issue preventing access to the container registry. Look in the describe pod text file to obtain the hostname of the Kubernetes node.

Why do we get ImagePullBackOff in Kubernetes?

The status ImagePullBackOff means that a container could not start because Kubernetes could not pull a container image (for reasons such as invalid image name, or pulling from a private registry without imagePullSecret ).

Why is Kubernetes killing my pod?

The OOMKilled error, also indicated by exit code 137, means that a container or pod was terminated because they used more memory than allowed. OOM stands for “Out Of Memory”. Kubernetes allows pods to limit the resources their containers are allowed to utilize on the host machine.

Why is Kubernetes pod restarting?

A restarting container can indicate problems with memory (see the Out of Memory section), cpu usage, or just an application exiting prematurely. If a container is being restarted because of CPU usage, try increasing the requested and limit amounts for CPU in the pod spec.

How do I stop Kubernetes restarting pod?

You will need to change the restart policy of the pod: A PodSpec has a restartPolicy field with possible values Always, OnFailure, and Never. The default value is Always. restartPolicy applies to all Containers in the Pod.

What are the possible causes of ErrImagePull?

The status ErrImagePull is displayed when kubelet tried to start a container in the Pod, but something was wrong with the image specified in your Pod, Deployment, or ReplicaSet manifest.


2 Answers

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
like image 108
Lucas Avatar answered Oct 13 '22 05:10

Lucas


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.
like image 28
Rico Avatar answered Oct 13 '22 04:10

Rico