<p>I have been trying out to deploy a test container with the dockerfile for my test container as below which when deployed on the Kubernetes the Pod goes into CrashLoopBackOff. What would be the possible reasons for the failure ?</p>
<p><em>Dockerfile for my test container:</em></p>
<pre><code>FROM docker.asdfasdf.com/alpine:3.14
RUN apk add netcat-openbsd
ENTRYPOINT [&quot;/bin/sh&quot;, &quot;-c&quot;, &quot;nc -l 8080 &amp;&quot;]
</code></pre>
<p>State of the container when deployed on kubernetes (describe pod info)</p>
<pre><code>main:
    Container ID:   docker://d845d4fb4asdf78sdfasdf8asdfasdf9asdfasda7
    Image:          asdf.sdfad.com/xyz/test1:asdfasdfasdfasdf
    Image ID:       docker-pullable://asdf.sdfad.com/xyz/test1:asdfasdfasdfasdf@sha256:a643c0e227a27ds5d4e78a9b50b894e1c934d95f88ddsdswvbc
    Ports:          8080/TCP, 8081/TCP
    Host Ports:     0/TCP, 0/TCP
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Thu, 26 May 2022 00:01:55 +0100
      Finished:     Thu, 26 May 2022 00:01:55 +0100
    Ready:          False
    Restart Count:  6
    Limits:
      memory:  1Gi
    Requests:
      cpu:      1
      memory:   500Mi
    Liveness:   http-get http://:8080/sadf/healthcheck delay=30s timeout=1s period=15s #success=1 #failure=3
    Readiness:  http-get http://:8080/asdf/healthcheck delay=20s timeout=1s period=5s #success=1 #failure=3
Events:
  Type     Reason               Age                From               Message
  ----     ------               ----               ----               -------

Normal   Created              10m (x2 over 10m)  kubelet            Created container main
  Warning  FailedPreStopHook    10m (x2 over 10m)  kubelet            Exec lifecycle hook ([sh -c rm heartbeat.txt &amp;&amp; sleep 30]) for Container &quot;main&quot; in Pod &quot;test1--avi--default-76b6d7c76b-s9jdt_test1-dev(asdfc-ava45-45ae-78d-fgghh7765532)&quot; failed - error: rpc error: code = Unknown desc = container not running (main), message: &quot;&quot;
  Normal   Killing              10m (x2 over 10m)  kubelet            FailedPostStartHook
  Warning  FailedPostStartHook  10m (x2 over 10m)  kubelet            Exec lifecycle hook ([sh -c dirname heartbeat.txt | xargs mkdir -p &amp;&amp; touch heartbeat.txt
]) for Container &quot;main&quot; in Pod &quot;test1--avi--default-76b6d7c76b-s9jdt_test1-dev(asdfc-ava45-45ae-78d-fgghh7765532)&quot; failed - error: rpc error: code = Unknown desc = container not running (main), message: &quot;&quot;
  Normal   Started  10m (x2 over 10m)   kubelet  Started container main
  Warning  BackOff  21s (x58 over 10m)  kubelet  Back-off restarting failed container
</code></pre>

Avi
<p>Entrypoint is: <code>&quot;nc -l 8080 &amp;&quot;</code></p>
<p><code>netcat</code> behavior is: handle request → print it into stdout → exit</p>
<p>So your first healthcheck: <code>http-get http://:8080/sadf/healthcheck delay=30s timeout=1s period=15s #success=1 #failure=3</code> doing this first request and after that <code>nc</code> exiting. Because of it: <code>#success=1 #failure=3</code></p>
<p>For example you may set entrypoint as</p>
<pre><code>[&quot;/bin/sh&quot;, &quot;-c&quot;, &quot;while true; do nc -l 8080; echo 'restarting netcat'; done&quot;]
</code></pre>
<p><code>while</code> loop will restart <code>nc</code> anytime it exit</p>
<p>Another (better) option is to use <code>-k</code> (<code>--keep-open</code>) argument to keep <code>nc</code> connection open:</p>
<pre><code>ENTRYPOINT [&quot;nc&quot;, &quot;-k&quot;, &quot;-l&quot;, &quot;8080&quot;]
</code></pre>
