<p>Trying to install a sample container App using Pod in my local environment
I'm using kubernates cluster coming with docker desktop. </p>

<p>I'm creating the Pod using bellow command with the YML file
kubectl create -f test_image_pull.yml</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
# value must be lower case
  name: sample-python-web-app
spec:
  containers:
    - name: sample-hello-world
      image: local/sample:latest
      imagePullPolicy: Always
      command: ["echo", "SUCCESS"]

</code></pre>

<p>docker file used to build the image and this container running without any issue if u run with docker run</p>

<pre><code># Use official runtime python
FROM python:2.7-slim

# set work directory to app

WORKDIR /app
# Copy current directory
COPY . /app

# install needed packages
RUN pip install --trusted-host pypi.python.org -r requirement.txt

# Make port 80 available to outside container

EXPOSE 80

# Define environment variable

ENV NAME World

# Run app.py when the container launches

CMD ["python" , "app.py"]


</code></pre>

<pre><code>from flask import Flask
from redis import Redis, RedisError
import os
import socket


#connect to redis
redis = Redis(host="redis", db=0, socket_connect_timeout=2, socket_timeout=2)
app = Flask(__name__)

@app.route("/")

def hello():
    try:
       visits = redis.incr("counter")
    except RedisError:
        visits = "&lt;i&gt;cannot connect to Redis, counter disabled&lt;/i&gt;"

    html = "&lt;h3&gt;Hello {name}!&lt;/h3&gt;" \
            "&lt;b&gt;Hostname:&lt;/b&gt; {hostname}&lt;br/&gt;"  \
            "&lt;b&gt;Visits:&lt;/b&gt; {visits}"


    return html.format (
              name=os.getenv("NAME", "world"),
              hostname=socket.gethostname(),
              visits=visits  
            )

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=80)            

</code></pre>

<pre><code>Flask
Redis


</code></pre>

<p>Once I describe the pod it shows me below error</p>

<p>kubectl describe pod sample-python-web-app</p>

<pre><code>Events:
  Type     Reason     Age                  From                     Message
  ----     ------     ----                 ----                     -------
  Normal   Scheduled  3m25s                default-scheduler        Successfully assigned default/sample-python-web-app to docker-desktop
  Normal   Pulling    97s (x4 over 3m22s)  kubelet, docker-desktop  Pulling image "local/sample:latest"
  Warning  Failed     94s (x4 over 3m17s)  kubelet, docker-desktop  Failed to pull image "local/sample:latest": rpc error: code = Unknown desc = Error response from daemon: pull access denied for local/sample, repository does not exist or may require 'docker login': denied: requested access to the resource is denied
  Warning  Failed     94s (x4 over 3m17s)  kubelet, docker-desktop  Error: ErrImagePull
  Normal   BackOff    78s (x6 over 3m16s)  kubelet, docker-desktop  Back-off pulling image "local/sample:latest"
  Warning  Failed     66s (x7 over 3m16s)  kubelet, docker-desktop  Error: ImagePullBackOff
</code></pre>

<p>Kubernetes pulls container images from a Docker Registry. Per the <a href="https://kubernetes.io/docs/concepts/containers/images/" rel="noreferrer">doc</a>:</p>

<blockquote>
  <p>You create your Docker image and push it to a registry before
  referring to it in a Kubernetes pod.</p>
</blockquote>

<p>Moreover:</p>

<blockquote>
  <p>The <code>image</code> property of a container supports the same syntax as the
  docker command does, including private registries and tags.</p>
</blockquote>

<p>So, the way the image is referenced in the pod's spec - "image: local/sample:latest" - Kubernetes looks on Docker Hub for the image in repository <em>named</em> "local".</p>

<p>You can push the image to Docker Hub or some other external Docker Registry, public or private; you can host Docker Registry on the Kubernetes cluster; or, you can run a Docker Registry locally, in a container.</p>

<p>To <a href="https://docs.docker.com/registry/deploying/#run-a-local-registry" rel="noreferrer">run a Docker registry locally</a>:</p>

<pre><code>docker run -d -p 5000:5000 --restart=always --name registry registry:2
</code></pre>

<p>Next, find what is the IP address of the host - below I'll use <code>10.0.2.1</code> as an example.</p>

<p>Then, assuming the image name is "local/sample:latest", tag the image:</p>

<pre><code>docker tag local/sample:latest 10.0.2.1:5000/local/sample:latest
</code></pre>

<p>...and push the image to the local registry:</p>

<pre><code>docker push 10.0.2.1:5000/local/sample:latest
</code></pre>

<p>Next, change in pod's configuration YAML how the image is referenced - from</p>

<pre><code>    image: local/sample:latest
</code></pre>

<p>to</p>

<pre><code>    image: 10.0.2.1:5000/local/sample:latest
</code></pre>

<p>Restart the pod.</p>

<p>EDIT: Most likely the local Docker daemon will have to be configured to treat the local Docker registry as <a href="https://docs.docker.com/engine/reference/commandline/dockerd/#insecure-registries" rel="noreferrer">insecure</a>. One way to configure that is described <a href="https://docs.docker.com/registry/insecure/" rel="noreferrer">here</a> - just replace "myregistrydomain.com" with the host's IP (e.g. <code>10.0.2.1</code>). Docker Desktop also allows to edit daemon's configuration file <a href="https://docs.docker.com/docker-for-mac/#docker-engine" rel="noreferrer">through the GUI</a>.</p>
