<p>I have a problem to deploy docker image via kubernetes.</p>

<p>One issue is that, we cannot use any docker image registry service e.g. docker hub or any cloud services. But, yes I have docker images as .tar file.</p>

<p>However, it always fails with following message</p>

<pre><code>Warning  Failed     1s         kubelet, dell20    

Failed to pull image "test:latest": rpc
error: code = Unknown
desc = failed to resolve image "docker.io/library/test:latest":
failed to do request: Head https://registry-1.docker.io/v2/library/test/manifests/latest: dial tcp i/o timeout
</code></pre>

<p>I also change deployment description with IfNotPresent or Never. In this case it will fail anyway with ErrImageNeverPull.</p>

<p>My guess is: kubernetes tries to use Docker Hub anyway, since it <a href="https://registry-1.docker.io" rel="noreferrer">https://registry-1.docker.io</a> in order to pull the image. I just want to use tar docker image in local disk, rather than pulling from some services.</p>

<p>And yes the image is in docker:</p>

<pre><code>docker images
REPOSITORY  TAG    IMAGE ID      CREATED     SIZE
test        latest 9f4916a0780c  6 days ago  1.72GB
</code></pre>

<p>Can anyone give me any advices on this problem?</p>

zedoul
<p>I was successful with using local image with Kubernetes cluster. I provided the explanation with example below: </p>

<p>The only prerequisite is that you need to make sure you have access to upload this image directly to nodes. </p>

<h3>Create the image</h3>

<p>Pull the default nginx image from docker registry with below command: </p>

<p><code>$ docker pull nginx:1.17.5</code></p>

<p>Nginx image is used only for demonstration purposes. </p>

<p>Tag this image with new name as <code>nginx-local</code>  with command: </p>

<p><code>$ docker tag nginx:1.17.5 nginx-local:1.17.5</code></p>

<p>Save this image as nginx-local.tar executing command: </p>

<p><code>$ docker save nginx-local:1.17.5 &gt; nginx-local.tar</code></p>

<p>Link to documentation: <a href="https://docs.docker.com/engine/reference/commandline/save/" rel="noreferrer">docker save</a></p>

<p><strong>File <code>nginx-local.tar</code> is used as your image.</strong></p>

<h3>Copy the image to all of the nodes</h3>

<p><strong>The problem with this technique is that you need to ensure all of the nodes have this image.</strong><br>
Lack of image will result in failed pod creation. </p>

<p>To copy it you can use <code>scp</code>. It's secure way to transer files between machines.<br>
Example command for scp: </p>

<pre><code>$ scp /path/to/your/file/nginx-local.tar user@ip_adddress:/where/you/want/it/nginx-local.tar
</code></pre>

<p>If image is already on the node, you will need to load it into local docker image repository with command:</p>

<p><code>$ docker load -i nginx-local.tar</code></p>

<p>To ensure that image is loaded invoke command </p>

<p><code>$ docker images | grep nginx-local</code></p>

<p>Link to documentation: <a href="https://docs.docker.com/engine/reference/commandline/load/" rel="noreferrer">docker load</a>: </p>

<p>It should show something like that: </p>

<pre><code>docker images | grep nginx
nginx-local                                           1.17.5              540a289bab6c        3 weeks ago         126MB
</code></pre>

<h3>Creating deployment with local image</h3>

<p>The last part is to create deployment with use of nginx-local image. </p>

<p><strong>Please note that:</strong></p>

<ul>
<li>The image version is <strong>explicitly typed inside</strong> yaml file. </li>
<li>ImagePullPolicy is set to <strong>Never</strong>. <a href="https://kubernetes.io/docs/concepts/containers/images/" rel="noreferrer">ImagePullPolicy</a></li>
</ul>

<p><strong>Without this options the pod creation will fail.</strong></p>

<p>Below is example deployment which uses exactly that image: </p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx-local
  namespace: default
spec:
  selector:
    matchLabels:
      run: nginx-local
  replicas: 5 
  template:
    metadata:
      labels:
        run: nginx-local
    spec:
      containers:
      - image: nginx-local:1.17.5
        imagePullPolicy: Never
        name: nginx-local
        ports:
        - containerPort: 80
</code></pre>

<p>Create this deployment with command: 
<code>$ kubectl create -f local-test.yaml</code></p>

<p>The result was that pods were created successfully as shown below: </p>

<pre><code>NAME                           READY   STATUS    RESTARTS   AGE
nginx-local-84ddb99b55-7vpvd   1/1     Running   0          2m15s
nginx-local-84ddb99b55-fgb2n   1/1     Running   0          2m15s
nginx-local-84ddb99b55-jlpz8   1/1     Running   0          2m15s
nginx-local-84ddb99b55-kzgw5   1/1     Running   0          2m15s
nginx-local-84ddb99b55-mc7rw   1/1     Running   0          2m15s
</code></pre>

<p>This operation was successful but I would recommend you to use local docker repository. It will easier management process with images and will be inside your infrastructure.
Link to documentation about it:  <a href="https://docs.docker.com/registry/" rel="noreferrer">Local Docker Registry </a></p>
