Docker for Windows Kubernetes pod gets ImagePullBackOff after creating a new deployment
I just had the exact same problem. Boils down to the imagePullPolicy
:
PC:~$ kubectl explain deployment.spec.template.spec.containers.imagePullPolicyKIND: DeploymentVERSION: extensions/v1beta1FIELD: 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
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.
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/v1kind: Deploymentmetadata: name: web-app-deployment labels: app: web-appspec: 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