<p>I am running <code>nodejs</code> based application on <code>kubernetes</code> and it's in <code>CrashLoopBackOff</code> state.</p>

<pre><code>kubectl logs api-5db677ff5-p824m

&gt; api@0.0.1 staging /home/node
&gt; NODE_ENV=staging node src/loader.js

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! api@0.0.1 staging: `NODE_ENV=staging node src/loader.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the api@0.0.1 staging script.
npm ERR! This is probably not a problem with npm. There is likely additional 
logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/node/.npm/_logs/2019-04-04T14_24_26_908Z-debug.log
</code></pre>

<p>There is not much information in logs and I cannot access the complete log file from the given path in container.</p>

<p>When I try check that file in container:</p>

<pre><code>kubectl exec -it api-5db677ff5-p824m -- /bin/bash
</code></pre>

<p>It's giving me this error:</p>

<blockquote>
  <p>error: unable to upgrade connection: container not found ("api")</p>
</blockquote>

<p>If you have access to the k8s node, you can access the logs of (all) the pods at <code>/var/log/pods</code>. </p>

<p>Alternatively, you can try to mount of PVC to your node pod and configure your node application to write to logs there. This will ensure that your crash logs are not destroyed when the container crashes.</p>

<p>Another similar approach is to override your pod container command with <code>sleep 3600</code> and then <code>exec</code> into the container to run your node application manually. Once the node process crashes and writes the logs, you can then view them (inside the container). </p>

<p>Hope this helps!</p>
