How to resolve ImagePullBackOff error in local?

9/22/2020

Net core application image and I am trying to create deployment in local kubernetes. I created docker image as below.

docker tag microservicestest:dev microservicestest .
docker build -t microservicestest .
docker run -d -p 8080:80 --name myapp microservicetest

Then I created deployment as below.

kubectl run microservicestest-deployment --image=microservicestest:latest --port 80 --replicas=3
kubectl expose deployment microservicestest-deployment --type=NodePort

then when I see Kubectl get pods I see below error

enter image description here

Below is the output when I run docker images

enter image description here

Below is the output

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
  creationTimestamp: "2020-09-22T04:29:14Z"
  generation: 1
  labels:
    run: microservicestest-deployment
  name: microservicestest-deployment
  namespace: default
  resourceVersion: "17282"
  selfLink: /apis/apps/v1/namespaces/default/deployments/microservicestest-deployment
  uid: bf75410a-d332-4016-9757-50d534114599
spec:
  progressDeadlineSeconds: 600
  replicas: 3
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      run: microservicestest-deployment
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: microservicestest-deployment
    spec:
      containers:
      - image: microservicestest:latest
        imagePullPolicy: Always
        name: microservicestest-deployment
        ports:
        - containerPort: 80
          protocol: TCP
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
status:
  conditions:
  - lastTransitionTime: "2020-09-22T04:29:14Z"
    lastUpdateTime: "2020-09-22T04:29:14Z"
    message: Deployment does not have minimum availability.
    reason: MinimumReplicasUnavailable
    status: "False"
    type: Available
  - lastTransitionTime: "2020-09-22T04:29:14Z"
    lastUpdateTime: "2020-09-22T04:29:14Z"
    message: ReplicaSet "microservicestest-deployment-5c67d587b9" is progressing.
    reason: ReplicaSetUpdated
    status: "True"
    type: Progressing
  observedGeneration: 1
  replicas: 3
  unavailableReplicas: 3
  updatedReplicas: 3

I am not able to understand why my pods are not able to pull the image from local. Can someone help me to identify the issue What I am making here. Any help would be appreciated. Thank you

-- Mr Perfect
containers
docker
kubectl
kubernetes

1 Answer

9/22/2020

if you are using minikube you first need to build the images in the docker hosted in the minikube machine doing this in your bash session eval $(minikube docker-env) for windows check here

then you need to tell Kubernetes your image pull policy to be Never or IfNotPresent to look for local images

spec:
     containers:
     - image: my-image:my-tag
       name: my-app
       imagePullPolicy: Never

check here the official documentation

By default, the kubelet tries to pull each image from the specified registry. However, if the imagePullPolicy property of the container is set to IfNotPresent or Never, then a local image is used (preferentially or exclusively, respectively).

as you are not using yaml file you can create the resources like this

kubectl run microservicestest-deployment --image=microservicestest:latest --image-pull-policy=Never --port 80 --replicas=3

kubectl expose deployment microservicestest-deployment --type=NodePort

-- cperez08
Source: StackOverflow