<p>I am new in Kubernetes, and I want to run the simple flask program on docker in Kubernetes. The image in docker could work successfully, but when I start the K8s.yaml with <code>kubectl apply -f k8s.yaml</code> and execute <code>minikube service flask-app-service</code> the web result reply fail with ERR_CONNECTION_REFUSED, and pods status <code>Error: ErrImageNeverPull</code>.</p>
<p>app.py:</p>
<pre class="lang-python prettyprint-override"><code># flask_app/app/app.py
from flask import Flask

app = Flask(__name__)

@app.route(&quot;/&quot;)
def hello():
    return &quot;Hello, World!&quot;


if __name__ == '__main__':
    app.debug = True
    app.run(debug=True, host='0.0.0.0')
</code></pre>
<p>Dockerfile:</p>
<pre class="lang-sh prettyprint-override"><code>FROM python:3.9

RUN mkdir /app
WORKDIR /app
ADD ./app /app/
RUN pip install -r requirement.txt

EXPOSE 5000
CMD [&quot;python&quot;, &quot;/app/app.py&quot;]
</code></pre>
<p>K8s.yaml:</p>
<pre class="lang-yaml prettyprint-override"><code>---
    apiVersion: v1
    kind: Service
    metadata:
      name: flask-app-service
    spec:
      selector:
        app: flask-app
      ports:
      - protocol: &quot;TCP&quot;
        port: 5000
        targetPort: 5000


    
---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: flask-app
    spec:
      selector:
        matchLabels:
          app: flask-app
      replicas: 3
      template:
        metadata:
          labels:
            app: flask-app
        spec:
          containers:
          - name: flask-app
            image: flask_app:latest
            imagePullPolicy: Never
            ports:
            - containerPort: 5000
</code></pre>
<p>After deploying I try to connect to <code>http://127.0.0.1:51145</code> from a browser, but it fails to connect with an <code>ERR_CONNECTION_REFUSED</code> message.  I have a <a href="https://i.stack.imgur.com/zXtW3.png" rel="nofollow noreferrer">screenshot showing a more detailed Chinese-language error message</a> if that detail is helpful.</p>
<hr />
<p>update:</p>
<p>After switch <code>imagePullPolicy</code> from <code>never</code> to <code>Always</code> or <code>IfNotPresent</code>, the pod still can't run
<a href="https://i.stack.imgur.com/gYTz9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gYTz9.png" alt="enter image description here" /></a>
I try the <code>docker images</code> command it show the image exist:
<a href="https://i.stack.imgur.com/F3xa3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/F3xa3.png" alt="enter image description here" /></a>
But when I pull image with docker pull, it show me the error:
<a href="https://i.stack.imgur.com/nKRbc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nKRbc.png" alt="enter image description here" /></a>
After docker login still not work:
<a href="https://i.stack.imgur.com/89XG2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/89XG2.png" alt="enter image description here" /></a></p>
<p>p.s. I follow the website to pratice: <a href="https://lukahuang.com/running-flask-on-minikube/" rel="nofollow noreferrer">https://lukahuang.com/running-flask-on-minikube/</a></p>

Howard
<p>Based on the error in the question:</p>
<blockquote>
<p>pods status Error: ErrImageNeverPull.</p>
</blockquote>
<p>pod doesn't start because you have <code>imagePullPolicy: Never</code> in your deployment manifest. Which means that if the image is missing, it won't be pulled anyway.</p>
<p>This is from official documentation:</p>
<blockquote>
<p>The imagePullPolicy for a container and the tag of the image affect
when the kubelet attempts to pull (download) the specified image.</p>
</blockquote>
<p>You need to switch it to <code>IfNotPresent</code> or <code>Always</code>.</p>
<p>See more in <a href="https://kubernetes.io/docs/concepts/containers/images/#image-pull-policy" rel="nofollow noreferrer">image pull policy</a>.</p>
<p>After everything is done correctly, pod status should be <code>running</code> and then you can connect to the pod and get the response back. See the example output:</p>
<pre><code>$ kubectl get pods
NAME     READY   STATUS    RESTARTS      AGE
ubuntu   1/1     Running   0             4d
</code></pre>
