2

I am trying to create a Kubernetes pod with the following config 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

However, I get an ImagePullBackOff, and when I use kubectl describe pod, here's what's shown:

Name:         mongodb-deployment-8f6675bc5-jzmvw
Namespace:    default
Priority:     0
Node:         minikube/192.168.64.2
Start Time:   Thu, 10 Dec 2020 16:30:21 +0800
Labels:       app=mongodb
              pod-template-hash=8f6675bc5
Annotations:  <none>
Status:       Pending
IP:           172.17.0.3
IPs:
  IP:           172.17.0.3
Controlled By:  ReplicaSet/mongodb-deployment-8f6675bc5
Containers:
  mongodb:
    Container ID:
    Image:          mongo
    Image ID:
    Port:           27017/TCP
    Host Port:      0/TCP
    State:          Waiting
      Reason:       ErrImagePull
    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 default-token-w5ltt (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  default-token-w5ltt:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-w5ltt
    Optional:    false
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  115m  default-scheduler  Successfully assigned default/mongodb-deployment-8f6675bc5-jzmvw to minikube
  Normal   Pulling    115m  kubelet            Pulling image "mongo"
  Warning  Failed     114m  kubelet            Failed to pull image "mongo": rpc error: code = Unknown desc = Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
  Warning  Failed     114m  kubelet            Error: ErrImagePull
  Normal   BackOff    114m  kubelet            Back-off pulling image "mongo"
  Warning  Failed     114m  kubelet            Error: ImagePullBackOff

I don't think it's a problem with the image/image name. Is there something wrong with my config file?

Any advice would be greatly appreciated!

Aidenhsy
  • 915
  • 2
  • 13
  • 28
  • I have deployed your config without any issues. Are you behind any proxy that might affect pulling images? Are you using private registry? Is there any output in `kubectl logs `? – kool Dec 10 '20 at 15:52
  • @MariuszK. if one is behind a proxy what is the way to fix the issue described above? I've set the http_proxy environment variable, to no avail. thanks. – Gifford N. May 06 '21 at 07:10

1 Answers1

0

There are few reasons for ImagePullBackOff error in Kubernetes, to determine it's cause you should run kubectl describe pod

Failed to pull image "mongo": rpc error: code = Unknown desc = Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

This error means that image cannot be pulled from your container registry.

You can try to login to docker using docker login command. If it fails you can try modifying your /etc/resolv.conf and adding nameserver 8.8.8.8 and then restarting docker using sudo systemctl restart docker.

Other cause might be using proxy or VPN connection. You can refer to answers in this question.

kool
  • 3,214
  • 1
  • 10
  • 26