<p>In Kubernetes I have a Pod that is no longer running, eg in <code>Completed</code>/<code>Terminated</code> state.  </p>

<p>I have <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#exec" rel="nofollow noreferrer"><code>describe</code></a> and <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#exec" rel="nofollow noreferrer"><code>logs</code></a>, but sometimes you need to <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#exec" rel="nofollow noreferrer"><code>exec</code></a> into a Pod to debug problems.  This isn't always possible to do in time whilst the Pod was running.</p>

<p>Is there a way to inspect a Pods filesystems post-mortem?<br>
Or a way to bring a Pod back replacing the CMD/ENTRYPOINT with <code>/bin/bash</code> or similar to have a poke around to see what happened?</p>

Jethro
<p>You can check previous logs of a pod by using <code>--previous</code> flag:</p>

<ol>
<li><code>kubectl logs my-pod --previous</code> <a href="https://kubernetes.io/docs/reference/kubectl/cheatsheet/#interacting-with-running-pods" rel="nofollow noreferrer">ref</a></li>
<li><code>kubectl logs my-pod -c my-container --previous</code> <a href="https://kubernetes.io/docs/reference/kubectl/cheatsheet/#interacting-with-running-pods" rel="nofollow noreferrer">ref</a></li>
</ol>

<p>On an event where you want to keep the container inside the pod alive then use the below code:</p>

<p><code>apiVersion: v1
kind: Pod
metadata:
  name: ubuntu
spec:
  containers:
  - name: ubuntu
    image: ubuntu:latest
    # Just spin &amp; wait forever
    command: [ "/bin/bash", "-c", "--" ]
    args: [ "while true; do sleep 30; done;" ]</code> <a href="https://stackoverflow.com/a/40093356/4451944">Ref</a></p>

<p>above the important lines are<br>
<code># Just spin &amp; wait forever
 command: [ "/bin/bash", "-c", "--" ]
 args: [ "while true; do sleep 30; done;" ]</code></p>
