Why am I getting an ErrImagePull error in this Kubernetes deployment?
Asked Answered
H

4

54

I'm trying to create a local Kubernetes deployment using Minikube, Docker Registry, and a demo node project.

The first thing I did was install Docker v1.12.3, then Minikube v0.12.2.

Then I created a Docker Registry container by running this command (via this tutorial, only running the first command below)

docker run -d -p 5000:5000 --name registry registry:2

Next I ran this minikube command to create a local kubernetes cluster:

minikube start --vm-driver="virtualbox" --insecure-registry="0.0.0.0:5000"

My project structure looks like this:

.
├── Dockerfile
└── server.js

and my Dockerfile looks like this:

FROM node:7.1.0
EXPOSE 8080
COPY server.js .
CMD node server.js

Then I built my own docker image and pushed it to my private repository:

docker build -t hello-node .
docker tag hello-node localhost:5000/hello-node
docker push localhost:5000/hello-node

Then I tried to run a deployment with this command:

kubectl run hello-node --image=localhost:5000/hello-node --port=8888

But then I get this:

sudo kubectl get pods --all-namespaces                                                                                                                             
NAMESPACE     NAME                          READY     STATUS         RESTARTS   AGE
default       hello-node-3745105022-gzs5a   0/1       ErrImagePull   0          11m
kube-system   kube-addon-manager-minikube   1/1       Running        4          10d
kube-system   kube-dns-v20-2x64k            3/3       Running        12         10d
kube-system   kubernetes-dashboard-mjpjv    1/1       Running        4          10d

I think I might be missing some kind of docker registry authentication, but as I'm googling I can't find something that I understand. Could someone please point me in the right direction?

Edit

After using ssh to access bash on the kubernetes VM and pull the hello-node image from my private registry by using this command:

minikube ssh
Boot2Docker version 1.11.1, build master : 901340f - Fri Jul  1 
22:52:19 UTC 2016
Docker version 1.11.1, build 5604cbe
docker@minikube:~$ sudo docker pull localhost:5000/hello-node
Using default tag: latest
Pulling repository localhost:5000/hello-node
Error while pulling image: Get http://localhost:5000/v1/repositories/hello-node/images: dial tcp 127.0.0.1:5000: getsockopt: connection refused

Is localhost:5000 the correct address to use within the kubernetes host VM?

Helve answered 15/11, 2016 at 1:4 Comment(1)
W
60

It looks like you're running the registry on the host. In fact, you need to run the registry inside the VM. You can point your docker client to the docker daemon inside the minikube VM by running this command first eval $(minikube docker-env) in your shell.

Then, you can run the docker build command on your host, but it will build inside the VM.

In fact, if your goal is to simply run the local version of your images, you should run the eval $(minikube docker-env) to point towards the docker daemon in your VM, and set the imagePullPolicy: IfNotPresent in your pod YAML. Then, kubernetes will use a locally built image if available.

Waldron answered 15/11, 2016 at 5:5 Comment(3)
what is the windows powershell equivalent?Cailean
I hit this question I had the same thought in my mind as @Cailean . A bit of digging, the windows 10 equivalent is minikube docker-env | Invoke-Expression. Source: this web pageRinge
I tried all this but I'm still getting: Failed to pull image "5ccf6e9a71a8": rpc error: code = Unknown desc = Error response from daemon: pull access denied for 5ccf6e9a71a8, repository does not exist or may require 'docker login': denied: requested access to the resource is deniedCaputo
S
9

Had a same issue with Docker-Desktop > Kubernetes and I tried setting imagePullPolicy to Never and it just worked.

As I understood from kubectl describe pod mypd, Kubectl was trying to pull the image, and of course this image doesn't exist on remote server, hence the failure.

The above property will avoid connecting to registry and will use image from docker local images cache.

spec:
  template:
    spec:
      containers:
        - image: my/local-image
          imagePullPolicy: Never
Supplement answered 25/7, 2021 at 16:54 Comment(0)
H
2

This article has resolved my similar error https://medium.com/swlh/how-to-run-locally-built-docker-images-in-kubernetes-b28fbc32cc1d

Add imagePullPolicy: Never

spec:
  template:
    metadata:
      name: hello-world-pod
    spec:
      containers:
      - name: hello-world
        image: forketyfork/hello-world
        imagePullPolicy: Never
      restartPolicy: Never

After that link your local container registry to minikube docker container registry.

Run the below command:

eval $(minikube -p minikube docker-env)

Now build your docker image and kubectl service again , That's it !

Higinbotham answered 8/11, 2022 at 15:24 Comment(0)
G
0

Follow these steps, for minikube

  1. Update values.yaml with pullPolicy: IfNotPresent
  2. Manually upload image in minikube using minikube image load
  3. Verify if image is uploaded using ssh in minikube vm
  4. Uninstall and reinstall existing deployment. You can see your existing deploymet using kubectl get deployment -w
Graciagracie answered 4/11, 2023 at 7:27 Comment(3)
Thanks for your help, but this question has already been answered.Helve
@NathanJones Okk, I am sorry, But I Just wanted to contribute an answer to this question for StackOverflow community. And, it's just that I discovered a different unique solution that wasn't already here except for the first step. This is also a very common problem related to kubernetes. And the solution that has been marked accepted didn't work for me. ThanksGraciagracie
You're right, sorry for the passive aggressive comment. Thanks for sharing what worked for you!Helve

© 2022 - 2024 — McMap. All rights reserved.