<p>I am trying to create a pod using my own docker image on localhost.</p>
<p>This is the dockerfile used to create the image :</p>
<pre><code>FROM centos:8

RUN yum install -y gdb

RUN yum group install -y &quot;Development Tools&quot;

CMD [&quot;/usr/bin/bash&quot;]
                   
</code></pre>
<p>The yaml file used to create the pod is this :</p>
<pre><code>---
 apiVersion: v1
 kind: Pod
 metadata:
   name: server
   labels:
     app: server
 spec:
   containers:
     - name: server
       imagePullPolicy: Never
       image: localhost:5000/server
       ports:
         - containerPort: 80



root@node1:~/test/server# docker images | grep server
server                                                 latest              82c5228a553d        3 hours ago         948MB
localhost.localdomain:5000/server                      latest              82c5228a553d        3 hours ago         948MB
localhost:5000/server                                  latest              82c5228a553d        3 hours ago         948MB
                                                                                     
</code></pre>
<p>The image has been pushed to localhost registry.</p>
<p>Following is the error I receive.</p>
<pre><code>root@node1:~/test/server# kubectl get pods
NAME     READY   STATUS             RESTARTS   AGE
server   0/1     CrashLoopBackOff   5          5m18s
</code></pre>
<p>The output of describe pod :</p>
<pre><code>    root@node1:~/test/server# kubectl describe pod server

    Name:         server
Namespace:    default
Priority:     0
Node:         node1/10.0.2.15
Start Time:   Mon, 07 Dec 2020 15:35:49 +0530
Labels:       app=server
Annotations:  cni.projectcalico.org/podIP: 10.233.90.192/32
              cni.projectcalico.org/podIPs: 10.233.90.192/32
Status:       Running
IP:           10.233.90.192
IPs:
  IP:  10.233.90.192
Containers:
  server:
    Container ID:   docker://c2982e677bf37ff11272f9ea3f68565e0120fb8ccfb1595393794746ee29b821
    Image:          localhost:5000/server
    Image ID:       docker-pullable://localhost.localdomain:5000/server@sha256:6bc8193296d46e1e6fa4cb849fa83cb49e5accc8b0c89a14d95928982ec9d8e9
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Mon, 07 Dec 2020 15:41:33 +0530
      Finished:     Mon, 07 Dec 2020 15:41:33 +0530
    Ready:          False
    Restart Count:  6
    Environment:    &lt;none&gt;
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-tb7wb (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  default-token-tb7wb:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-tb7wb
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  &lt;none&gt;
Tolerations:     node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason     Age                    From               Message
  ----     ------     ----                   ----               -------
  Normal   Scheduled  6m                     default-scheduler  Successfully assigned default/server to node1
  Normal   Pulled     4m34s (x5 over 5m59s)  kubelet            Container image &quot;localhost:5000/server&quot; already present on machine
  Normal   Created    4m34s (x5 over 5m59s)  kubelet            Created container server
  Normal   Started    4m34s (x5 over 5m59s)  kubelet            Started container server
  Warning  BackOff    56s (x25 over 5m58s)   kubelet            Back-off restarting failed container
</code></pre>
<p>I get no logs :</p>
<pre><code>root@node1:~/test/server# kubectl logs -f server
root@node1:~/test/server# 
</code></pre>
<p>I am unable to figure out whether the issue is with the container or yaml file for creating pod. Any help would be appreciated.</p>

<p>Posting this as <code>Community Wiki</code>.</p>
<p>As pointed by @David Maze in comment section.</p>
<blockquote>
<p>If docker run exits immediately, a Kubernetes Pod will always go into <code>CrashLoopBackOff</code> state. Your <code>Dockerfile</code> needs to <code>COPY</code> in or otherwise install and application and set its <code>CMD</code> to run it.</p>
</blockquote>
<p>Root cause can be also determined by <code>Exit Code</code>. In <a href="https://containersolutions.github.io/runbooks/posts/kubernetes/crashloopbackoff/" rel="nofollow noreferrer">3) Check the exit code</a> article, you can find a few exit codes like 0, 1, 128, 137 with description.</p>
<blockquote>
<p>3.1) Exit Code 0</p>
<p>This exit code implies that the specified container command completed ‘sucessfully’, but too often for Kubernetes to accept as working.</p>
</blockquote>
<p>In short story, your container was created, all action mentioned was executed and as there was nothing else to do, it exit with <code>Exit Code 0</code>.</p>
<blockquote>
<p>A <code>CrashLoopBackOff</code> error occurs when a pod startup fails repeatedly in Kubernetes.`</p>
</blockquote>
<p>Your image based on <code>centos</code> with few additional installations did not have any process in backgroud left, so it was categorized as <code>Completed</code>. As this happen so fast, kubernetes restarted it and it fall in loop.</p>
<pre><code>$ kubectl run centos --image=centos
$ kubectl get po -w
NAME     READY   STATUS             RESTARTS   AGE
centos   0/1     CrashLoopBackOff   1          5s
centos   0/1     Completed          2          17s
centos   0/1     CrashLoopBackOff   2          31s
centos   0/1     Completed          3          46s
centos   0/1     CrashLoopBackOff   3          58s
centos   1/1     Running            4          88s
centos   0/1     Completed          4          89s
centos   0/1     CrashLoopBackOff   4          102s
</code></pre>
<pre><code>$ kubectl describe po centos | grep 'Exit Code'
      Exit Code:    0
</code></pre>
<p>But when you have used <code>sleep 3600</code>, in your container, command <code>sleep</code> was executing for hour. After this time it would also exit with <code>Exit Code 0</code>.</p>
<p>Hope it clarified.</p>
