3

I am trying to create a Kubernetes deployment from local docker images. And using imagePullPolicy as Never such that Kubernetes would pick it up from local docker image imported via tar.

Environment

  •  SingleNodeMaster  # one node deployment
    

But Kubernetes always trying to fetch the private repository although local docker images are present.

Any pointers on how to debug and resolve the issue such that Kubernetes would pick the images from the local docker registry? Thank you.

Steps performed

  • docker load -i images.tar
  • docker images # displays images from myprivatehub.com/nginx/nginx-custom:v1.1.8
  • kubectl create -f local-test.yaml with imagepullPolicy as Never

Error

Pulling  pod/nginx-custom-6499765dbc-2fts2   Pulling image "myprivatehub.com/nginx/nginx-custom:v1.1.8" 
Failed   pod/nginx-custom-6499765dbc-2fts2   Error: ErrImagePull   
Failed   pod/nginx-custom-6499765dbc-2fts2   Failed to pull image "myprivatehub.com/nginx/nginx-custom:v1.1.8": rpc error: code = Unknown desc = failed to pull and unpack image "myprivatehub.com/nginx/nginx-custom:v1.1.8": failed to resolve reference "myprivatehub.com/nginx/nginx-custom:v1.1.8": failed to do request: Head "https://myprivatehub.com/v2/nginx/nginx-custom/manifests/v1.1.8": dial tcp: lookup myprivatehub.com: no such host
docker pull <imagename>

Error response from daemon: Get https://myprivatehub.com/v2/: dial tcp: lookup myprivatehub.com on 172.31.0.2:53: no such host
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx-custom
  namespace: default
spec:
  selector:
    matchLabels:
      run: nginx-custom
  replicas: 5 
  template:
    metadata:
      labels:
        run: nginx-custom
    spec:
      containers:
      - image: myprivatehub.com/nginx/nginx-custom:v1.1.8
        imagePullPolicy: Never
        name: nginx-custom
        ports:
        - containerPort: 80
Viswanatha Swamy
  • 699
  • 1
  • 10
  • 17
Mozhi
  • 757
  • 1
  • 11
  • 28
  • deleted my answer as it wasn't addressing your query. you can add the docker pull result to the question – P.... Jun 22 '21 at 04:47
  • @P.... Added docker pull imagename result to the question. Please let me know your comments. Thank you – Mozhi Jun 22 '21 at 04:50
  • check this https://docs.docker.com/registry/recipes/mirror/#how-does-it-work – P.... Jun 22 '21 at 05:00
  • since you have the image present in the `docker images` try changig the policy from `never` to `IfNotPresent` . not sure how to force it to use cache. – P.... Jun 22 '21 at 05:11
  • @P... Same issue appears that i posted in the question , its trying to fetch from registry rather referrin to local docker image. – Mozhi Jun 22 '21 at 05:15
  • Hope this helps https://stackoverflow.com/a/58932692/6309601 – P.... Jun 22 '21 at 05:26
  • Ya tried this before raising the question, but not working :( – Mozhi Jun 22 '21 at 05:30

2 Answers2

2

This happens due to container runtime being different than docker. I am using containerd , after switching container runtime to docker , it started working.

Mozhi
  • 757
  • 1
  • 11
  • 28
  • 1
    glad you figured it out, we should have started with this! – P.... Jun 22 '21 at 14:03
  • @Mozhi can you please let me know the process in which you switched from containerd to docker? I am facing the same issue. get nodes -o wide; this returns containerd:// instead of docker. – Soumya May 20 '22 at 12:06
  • 1
    @Soumya Please follow this one https://kubernetes.io/docs/tasks/administer-cluster/migrating-from-dockershim/change-runtime-containerd/ ( Unfortunately I don't exactly remember the steps that I have done ) but the above link should be a good start. Thank you – Mozhi May 20 '22 at 12:44
1

This is to update another approach that can be taken to achieve the similar result. In this case, one can use Docker Registry. Docker Registry Doc

We can create a Docker registry on the machine where Kubernetes is running and docker too is installed. One of the easiest way to achieve the same can be done as following:

  1. Create a local private docker registry. If the registry:2 image is not present, then it would download it and run.
sudo docker run -d -p 5000:5000 --restart=always --name registry registry:2
  1. Build the image or load the image from a tar as required. For my example, i am creating it to add it to the local repository.
sudo docker build -t coolapp:v1 .
  1. Once the build is done, create a tag with this image such that it represents a host and a port.
sudo docker tag coolapp:v1 localhost:5000/coolapp:v1
  1. Push the new tag to the local private registry
sudo docker push localhost:5000/coolapp:v1

Now in the Kubernetes YAML, we can specify the deployment as following:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mycoolapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mycoolapp
  template:
    metadata:
      labels:
        app: mycoolapp
    spec:
      containers:
        - name: mycoolapp
          image: localhost:5000/coolapp:v1
          ports:
            - containerPort: 3000

and we apply the YAML

sudo kubectl apply -f deployment.yaml

Once this is done, we will be able to see that Kubernetes has pulled the image from the local private repository and is running it.

Soumya
  • 1,350
  • 3
  • 19
  • 34