Home > Enterprise >  MongoDb ImagePullBackOff error in Kubernetes despite trying every SOF solution
MongoDb ImagePullBackOff error in Kubernetes despite trying every SOF solution

Time:08-30

I'm using minikube on a Fedora based machine to run a simple mongo-db deployment on my local machine but I'm constantly getting ImagePullBackOff error. Here is the yaml file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongodb-deployment
  labels:
    app: mongodb
spec:
 replicas: 1
 selector:
   matchLabels:
     app: mongodb
 template: 
  metadata:
    labels:
      app: mongodb
  spec:
    containers:
      - name: mongodb
        image: mongo
        ports:
            - containerPort: 27017
        env:
           - name: MONGO_INITDB_ROOT_USERNAME
             valueFrom:
              secretKeyRef:
                 name: mongodb-secret
                 key: mongo-root-username
           - name: MONGO_INITDB_ROOT_PASSWORD
             valueFrom:
              secretKeyRef:
                 name: mongodb-secret
                 key: mongo-root-password
 
 
apiVersion: v1
kind: Service
metadata:
   name: mongodb-service
spec:
  selector:
      app: mongodb
  ports:
     - protocol: TCP
       port: 27017
       targetPort: 27017

I tried to pull the image locally by using docker pull mongo, minikube image pull mongo & minikube image pull mongo-express several times while restarting docker and minikube several times.

Logining into dockerhub (both in broweser and through terminal didn't work)

I also tried to login into docker using docker login command and then modified my /etc/resolv.conf and adding nameserver 8.8.8.8 and then restartied docker using sudo systemctl restart docker but even that failed to work.

On running kubectl describe pod command I get this output:

Name:         mongodb-deployment-6bf8f4c466-85b2h
Namespace:    default
Priority:     0
Node:         minikube/192.168.49.2
Start Time:   Mon, 29 Aug 2022 23:04:12  0530
Labels:       app=mongodb
          pod-template-hash=6bf8f4c466
Annotations:  <none>
Status:       Pending
IP:           172.17.0.2
IPs:
  IP:           172.17.0.2
Controlled By:  ReplicaSet/mongodb-deployment-6bf8f4c466
Containers:
 mongodb:
   Container ID:   
   Image:          mongo
   Image ID:       
   Port:           27017/TCP
   Host Port:      0/TCP
   State:          Waiting
     Reason:       ImagePullBackOff
   Ready:          False
   Restart Count:  0
   Environment:
     MONGO_INITDB_ROOT_USERNAME:  <set to the key 'mongo-root-username' in secret 'mongodb-secret'>  
     Optional: false
     MONGO_INITDB_ROOT_PASSWORD:  <set to the key 'mongo-root-password' in secret 'mongodb-secret'>  
     Optional: false
   Mounts:
      
     /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-vlcxl (ro)
  Conditions:
       Type              Status
       Initialized       True 
       Ready             False 
       ContainersReady   False 
       PodScheduled      True 
  Volumes:
     kube-api-access-vlcxl:
     Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                         node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason          Age                  From               Message

  Normal   Scheduled       22m                  default-scheduler  Successfully assigned default/mongodb-deployment-6bf8f4c466-85b2h to minikube
  Warning  Failed          18m (x2 over 20m)    kubelet            Failed to pull image "mongo:latest": rpc error: code = Unknown desc = context deadline exceeded
  Warning  Failed          18m (x2 over 20m)    kubelet            Error: ErrImagePull
  Normal   BackOff         17m (x2 over 20m)    kubelet            Back-off pulling image "mongo:latest"
  Warning  Failed          17m (x2 over 20m)    kubelet            Error: ImagePullBackOff
  Normal   Pulling         17m (x3 over 22m)    kubelet            Pulling image "mongo:latest"
  Normal   SandboxChanged  11m                  kubelet            Pod sandbox changed, it will be killed and re-created.
  Normal   Pulling         3m59s (x4 over 11m)  kubelet            Pulling image "mongo:latest"
  Warning  Failed          2m (x4 over 9m16s)   kubelet            Failed to pull image "mongo:latest": rpc error: code = Unknown desc = context deadline exceeded
  Warning  Failed          2m (x4 over 9m16s)   kubelet            Error: ErrImagePull
  Normal   BackOff         83s (x7 over 9m15s)  kubelet            Back-off pulling image "mongo:latest"
  Warning  Failed          83s (x7 over 9m15s)  kubelet            Error: ImagePullBackOff

PS: Ignore any any spacing errors

CodePudding user response:

I think your internet connection is slow. The timeout to pull an image is 120 seconds, so kubectl could not pull the image in under 120 seconds.

First, pull the image via Docker

docker image pull mongo

Then load the downloaded image to minikube

minikube image load mongo

And then everything will work because now kubectl will use the image that is stored locally.

  • Related