<p>I try to deploy one docker image that I build and is not on a public or private registry. </p>

<p>I use the <code>imagePullPolicy: IfNotPresent</code> for the Kubernetes deployment.</p>

<p>I use kubeadm v1.12 the error:</p>

<pre><code>Normal   Scheduled       35s                default-scheduler       Successfully assigned default/test-777dd9bc96-chgc7 to ip-10-0-1-154
Normal   SandboxChanged  32s                kubelet, ip-10-0-1-154  Pod sandbox changed, it will be killed and re-created.
Normal   BackOff         30s (x3 over 31s)  kubelet, ip-10-0-1-154  Back-off pulling image "test_kube"
Warning  Failed          30s (x3 over 31s)  kubelet, ip-10-0-1-154  Error: ImagePullBackOff
Normal   Pulling         15s (x2 over 34s)  kubelet, ip-10-0-1-154  pulling image "test"
Warning  Failed          13s (x2 over 33s)  kubelet, ip-10-0-1-154  Failed to pull image "test": rpc error: code = Unknown desc = Error response from daemon: pull access denied for test_kube, repository does not exist or may require 'docker login'
Warning  Failed          13s (x2 over 33s)  kubelet, ip-10-0-1-154  Error: ErrImagePull
</code></pre>

<p>My deployment file: </p>

<pre><code>apiVersion: apps/v1beta1
kind: Deployment
vmetadata:
  name: test-kube
spec:
  template:
    metadata:
  labels:
    app: test
spec:
  containers:
  - name: test
    image: test
    imagePullPolicy: IfNotPresent
    ports:
    - containerPort: 3000
    env:
    - name: SECRET-KUBE
      valueFrom:
        secretKeyRef:
          name: secret-test
          key: username
</code></pre>

<blockquote>
  <p>docker images]</p>
</blockquote>

<pre><code>REPOSITORY  TAG
test   latest 
test   test  
</code></pre>

<p>In the deployment file i tried with     </p>

<blockquote>
  <p>image: test  and with image: test:test</p>
</blockquote>

<p>The same error:</p>

<blockquote>
  <p>Error: ErrImagePull</p>
</blockquote>

<p>You should have a docker private registry on the master node of the kubernetes cluster so that if the pod is deployed on a node to pull the image from there. You can find the steps to create a Kubernetes cluster with docker private registry at: <a href="http://dradoaica.blogspot.com/2019/01/kubernetes-cluster-with-docker-private.html" rel="nofollow noreferrer">Kubernetes cluster with docker private registry</a></p>

<p>6. Creating a docker private registry on master node</p>

<pre><code># Set basic auth.
rm -f /auth/*
mkdir -p /auth
docker run --entrypoint htpasswd registry:2 -Bbn test test &gt; /auth/htpasswd

docker rm registry -f
</code></pre>

<pre><code># Set certificates auth.
rm -f /certs/*
mkdir -p /certs
openssl genrsa 1024 &gt; /certs/registrykey.pem
chmod 400 /certs/registrykey.pem
openssl req -new -x509 -nodes -sha1 -days 365 -key /certs/registrykey.pem  -out /certs/registry.pem  -subj "/C=/ST=/L=/O=/OU=/CN=registry.com" &gt; /dev/null 2&gt;&amp;1
docker run -d -e REGISTRY_HTTP_ADDR=0.0.0.0:5000 -p 5000:5000 --restart=always --name registry -v `pwd`/auth:/auth -e "REGISTRY_AUTH=htpasswd" -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd -v `pwd`/certs:/certs -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/registry.pem -e REGISTRY_HTTP_TLS_KEY=/certs/registrykey.pem registry:2

# Create secret to be used in "imagePullSecrets" section of a pod
kubectl create secret docker-registry regsecret --docker-server=192.168.147.3:5000 --docker-username=test --docker-password=test --namespace=kube-system

# Push image in private registry.
docker tag test-image:latest 192.168.147.3:5000/test-image
docker push 192.168.147.3:5000/test-image
</code></pre>

<p>7. YAML example for pod with image from private registry</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: test-site
  labels:
    app: web
spec:
  containers:
    - name: test
  image: 192.168.147.3:5000/test-image:latest
    ports:
      - containerPort: 8000
  imagePullPolicy: Always
    imagePullSecrets:
      - name: regsecret
</code></pre>
