title: Back-off restarting failed container In Azure AKS
body: <p>Linux container pod, with docker images from Azure Container registry, keeps restarting with restartPolicy as Always. Pod description is as below.</p>
  
  <pre><code>kubectl describe pod example-pod
  
  ...
  
  State:          Waiting
        Reason:       CrashLoopBackOff
      Last State:     Terminated
        Reason:       Completed
        Exit Code:    0
        Started:      Thu, 11 Jun 2020 03:27:11 +0000
        Finished:     Thu, 11 Jun 2020 03:27:12 +0000
  ...
  Back-off restarting failed container
  
  </code></pre>
  
  <p>This pod is created with secret to access ACR registry repository. 
    Reason is that pod completes execution successfully with exit code 0. However, It should keep listening at particular port number. Microsoft document link is at this URL <a href="https://docs.microsoft.com/en-us/azure/container-instances/container-instances-troubleshooting" rel="nofollow noreferrer">Container Group Runtime</a> under header "Container continually exits and restarts"</p>
  
  <p><strong>deployment-example.yml</strong> file content is as below.</p>
  
  <pre><code>apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: example-deployment
    namespace: development
    labels:
      app: example
  spec:
    replicas: 1
    selector:
      matchLabels:
        app: example
    template:
      metadata:
        labels:
          app: example
      spec:
        containers:
        - name: example
          image: contentocr.azurecr.io/example:latest
          #command: ["ping -t localhost"]
          imagePullPolicy: Always
          ports:
          - name: http-port
            containerPort: 3000
        imagePullSecrets:
          - name: regpass
        restartPolicy: Always
        nodeSelector:
          agent: linux
  ---
  apiVersion: v1
  kind: Service
  metadata:
    name: example
    namespace: development
    labels:
      app: example
  spec:
    ports:
    - name: http-port
      port: 3000
      targetPort: 3000
    selector:
        app: example
    type: LoadBalancer
  </code></pre>
  
  <p>Output of <em>kubectl get events</em> is as below.</p>
  
  <pre><code>3m39s       Normal    Scheduled              pod/example-deployment-5dc964fcf8-gbm5t    Successfully assigned development/example-deployment-5dc964fcf8-gbm5t to aks-agentpool-18342716-vmss000000
  2m6s        Normal    Pulling                pod/example-deployment-5dc964fcf8-gbm5t    Pulling image "contentocr.azurecr.io/example:latest"
  2m5s        Normal    Pulled                 pod/example-deployment-5dc964fcf8-gbm5t    Successfully pulled image "contentocr.azurecr.io/example:latest"
  2m5s        Normal    Created                pod/example-deployment-5dc964fcf8-gbm5t    Created container example
  2m49s       Normal    Started                pod/example-deployment-5dc964fcf8-gbm5t    Started container example
  2m20s       Warning   BackOff                pod/example-deployment-5dc964fcf8-gbm5t    Back-off restarting failed container
  6m6s        Normal    SuccessfulCreate       replicaset/example-deployment-5dc964fcf8   Created pod: example-deployment-5dc964fcf8-2fdt5
  3m39s       Normal    SuccessfulCreate       replicaset/example-deployment-5dc964fcf8   Created pod: example-deployment-5dc964fcf8-gbm5t
  6m6s        Normal    ScalingReplicaSet      deployment/example-deployment              Scaled up replica set example-deployment-5dc964fcf8 to 1
  3m39s       Normal    ScalingReplicaSet      deployment/example-deployment              Scaled up replica set example-deployment-5dc964fcf8 to 1
  3m38s       Normal    EnsuringLoadBalancer   service/example                            Ensuring load balancer
  3m34s       Normal    EnsuredLoadBalancer    service/example                            Ensured load balancer
  </code></pre>
  
  <p>Docker file entry point is like ENTRYPOINT <em>["npm", "start"]</em> with <em>CMD ["tail -f /dev/null/"]</em></p>