<p>I'm running a node application <a href="https://github.com/awslabs/amazon-kinesis-client-nodejs" rel="nofollow noreferrer">built on top of AWS's java KCL lib</a> on k8s.</p>
<p>Every 5 minutes or so the container crashe with &quot;CrashLoopBackOff&quot; and restarts - I can't figure out why.</p>
<p>The container logs show no errors and at some point the stream simply ends with:</p>
<pre><code>Stream closed EOF for sol/etl-sol-onchain-tx-parse-6b7d8f4c94-tf8tc (parse)
</code></pre>
<p>The pod events show no useful info either, looking like this:</p>
<pre><code>│     State:          Running                                                                               
│       Started:      Sun, 08 May 2022 10:06:36 -0400                                                       
│     Last State:     Terminated                                                                            
│       Reason:       Completed                                                                             
│       Exit Code:    0                                                                                     
│       Started:      Sun, 08 May 2022 09:58:42 -0400                                                       
│       Finished:     Sun, 08 May 2022 10:03:43 -0400                                                       
│     Ready:          True                                                                                  
│     Restart Count:  6
</code></pre>
<p>How is it possible that it says &quot;Completed&quot; with exit code 0? The container is a never ending process, it should never complete.</p>
<p>CPU/mem requests are used 25-50% at most.</p>
<p>What else might be causing this? The container is supposed to be using 4-7 threads (not sure if green) - maybe that's the issue? Running it on a M5. large (2 vCPUs, 8gb ram).</p>

ilmoi
<p>Error code 0 means the application terminated with a success -- although this can be misleading depending on the application. For example, if your code says to exit with code 0 on an error, this is what happens.</p>
<p>Kubernetes deployments will restart containers regardless of how they terminated -- success or failure.</p>
<p>A container is NOT a never-ending process. It can (and does) terminate when required to. For example, when you are running <code>cronjobs</code> or <code>jobs</code></p>
<p>Going back to your issue. We don't know what your application is doing, other than it is a node app. Is it processing something and then terminating when it finishes its queue?</p>
<p>Try to reproduce the issue by running the container locally using something like:</p>
<p><code>docker run -it path/to/image</code></p>
<p>(If you need to mount volumes, do so)</p>
<p>If the container runs, processes, and terminates, do:</p>
<p><code>echo $?</code></p>
<p>This will return the error code of the last command, if this returns 0, you have replicated what Kubernetes is seeing.</p>
<p>If this is the case, the two ways you can rectify this:</p>
<ol>
<li>Change the way the code is written to constantly check for new work so that instead of exiting with zero, it then goes back to check for new work.</li>
<li>Change the way you set up the Kubernetes resources and use either a <a href="https://kubernetes.io/docs/concepts/workloads/controllers/job/" rel="nofollow noreferrer">Job</a> (for a one-time run), or a <a href="https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/" rel="nofollow noreferrer">CronJob</a> (for a scheduled, repeating run). This won't require you to change your code in any way.</li>
</ol>
