<p>I am trying to deploy application from my personal docker registry into Azure AKS pods.
I have python application that only logs some output:</p>

<pre><code>import time
import logging

logger = logging.getLogger('main')
logger.setLevel(logging.INFO)

handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)

def main():
    logger.info('This is test')
    time.sleep(5)


while True:
    try:
        main()
    except Exception:
        logger.critical('Something critical.', exc_info=1)

    logger.info('Sleep for 5 seconds')
    time.sleep(5)
</code></pre>

<p>And this is my Dockerfile:</p>

<pre><code>FROM python:3.7-alpine

RUN apk update &amp;&amp; apk upgrade

ARG APP_DIR=/app
RUN mkdir -p ${APP_DIR}
WORKDIR ${APP_DIR}

COPY requirements.txt .

RUN \
 apk add --no-cache --virtual .build-deps gcc python3-dev musl-dev linux-headers &amp;&amp; \
 python3 -m pip install -r requirements.txt --no-cache-dir &amp;&amp; \
 apk --purge del .build-deps

COPY app .

ENTRYPOINT [ "python", "-u", "run.py" ]
</code></pre>

<p>I am able to run the container on my local computer, here some logs:</p>

<pre><code>docker logs -tf my-container
2020-02-07T10:26:57.939062754Z 2020-02-07 10:26:57,938 - main - INFO - This is test
2020-02-07T10:27:02.944500969Z 2020-02-07 10:27:02,943 - main - INFO - Sleep for 5 seconds
2020-02-07T10:27:07.948643749Z 2020-02-07 10:27:07,948 - main - INFO - This is test
2020-02-07T10:27:12.953683767Z 2020-02-07 10:27:12,953 - main - INFO - Sleep for 5 seconds
2020-02-07T10:27:17.955954057Z 2020-02-07 10:27:17,955 - main - INFO - This is test
2020-02-07T10:27:22.960453835Z 2020-02-07 10:27:22,959 - main - INFO - Sleep for 5 seconds
2020-02-07T10:27:27.964402790Z 2020-02-07 10:27:27,963 - main - INFO - This is test
2020-02-07T10:27:32.968647112Z 2020-02-07 10:27:32,967 - main - INFO - Sleep for 5 seconds
</code></pre>

<p>I am trying to deploy pod with this yaml file with <code>kubectl apply -f onepod.yaml</code>:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: my-container
  labels:
    platform: xxx
    event: yyy
    protocol: zzz
spec:
    imagePullSecrets:
    - name: myregistry
    containers:
    - name: my-container
      image: mypersonalregistry/my-container:test
</code></pre>

<p>The pod is created but keep <code>CrashLoopBackOff</code> status without any output logs via <code>kubectl logs</code> command. I tried <code>kubectl describe pod</code> but in events are nothing usefull:</p>

<pre><code>Name:         my-container
Namespace:    default
Priority:     0
Node:         aks-agentpool-56095163-vmss000000/10.240.0.4
Start Time:   Fri, 07 Feb 2020 11:41:48 +0100
Labels:       event=yyy
              platform=xxx
              protocol=zzz
Annotations:  kubectl.kubernetes.io/last-applied-configuration:
                {"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"labels":{"event":"yyy","platform":"xxx","protocol":"zzz"},"name":"my-container...
Status:       Running
IP:           10.244.1.33
IPs:          &lt;none&gt;
Containers:
  my-container:
    Container ID:   docker://c497674f86deadca2ef874f8a94361e26c770314e9cff1729bf20b5943d1a700
    Image:          mypersonalregistry/my-container:test
    Image ID:       docker-pullable://mypersonalregistry/my-container@sha256:c4208f42fea9a99dcb3b5ad8b53bac5e39bc54b8d89a577f85fec1a94535bc39
    Port:           &lt;none&gt;
    Host Port:      &lt;none&gt;
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Fri, 07 Feb 2020 12:28:10 +0100
      Finished:     Fri, 07 Feb 2020 12:28:10 +0100
    Ready:          False
    Restart Count:  14
    Environment:    &lt;none&gt;
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-lv75n (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  default-token-lv75n:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-lv75n
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  &lt;none&gt;
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason     Age                    From                                        Message
  ----     ------     ----                   ----                                        -------
  Normal   Scheduled  49m                    default-scheduler                           Successfully assigned default/my-container to aks-agentpool-56095163-vmss000000
  Normal   Pulled     48m (x5 over 49m)      kubelet, aks-agentpool-56095163-vmss000000  Container image "mypersonalregistry/my-container:test" already present on machine
  Normal   Created    48m (x5 over 49m)      kubelet, aks-agentpool-56095163-vmss000000  Created container my-container
  Normal   Started    48m (x5 over 49m)      kubelet, aks-agentpool-56095163-vmss000000  Started container my-container
  Warning  BackOff    4m55s (x210 over 49m)  kubelet, aks-agentpool-56095163-vmss000000  Back-off restarting failed container
</code></pre>

<p>How can I find out, why does it work on my computer but not in kubernetes cluster?</p>

dorinand
<p>So the porblem was with pulling latest version of my image. More <a href="https://kubernetes.io/docs/concepts/containers/images/#updating-images" rel="nofollow noreferrer">here</a>:</p>

<blockquote>
  <p>The default pull policy is IfNotPresent which causes the Kubelet to skip pulling an image if it already exists.</p>
</blockquote>

<p>So it still run the first version of <code>my-container</code> with tag <code>test</code> and never download new one even when it is in my registry.</p>

<p>Solution is add this line to yaml file:</p>

<pre><code>imagePullPolicy: Always
</code></pre>
