skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

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


  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search