K8S Failed to pull image from local repo

3/11/2019

I have an image in my docker repository. I an trying to create POD out of it but K8S is giving the following error.

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

It seems K8S is connecting to https://registry-1.docker.io/v2/ instead of taking from local docker repository.

How to make K8S take image for local docker repository ?

-- Chandu
docker
kubernetes

3 Answers

3/12/2019

Kubernetes supports a special type of secret that you can create that will be used to fetch images for your pods. More details here

-- Semah Mhamdi
Source: StackOverflow

3/18/2019

If you use single node in your cluster, make sure this docker image is available on this node. You can check via

docker image ls

Also set the imagePullPolicy to Never, otherwise Kubernetes will try to download the image.

Multiple node cluster, you can use docker registry image. Use a local registry:

docker run -d -p 5000:5000 --restart=always --name registry registry:2

Now tag your image properly:

docker tag ubuntu <dns-name-of-machine>:5000/ubuntu

dns name of the machine running registry container should be reachable by all nodes in network

Now push your image to local registry:

docker push <dns-name-of-machine>:5000/ubuntu

You should be able to pull it back:

docker pull <dns-name-of-machine>:5000/ubuntu

Now change your yaml file to use local registry.

-- coolinuxoid
Source: StackOverflow

3/11/2019

imagePullPolicy should be set to IfNotPresent to pull images from local docker repo

-- Chandu
Source: StackOverflow