In Kubernetes I have a Pod that is no longer running, eg in Completed
/Terminated
state.
I have describe
and logs
, but sometimes you need to exec
into a Pod to debug problems. This isn't always possible to do in time whilst the Pod was running.
Is there a way to inspect a Pods filesystems post-mortem?
Or a way to bring a Pod back replacing the CMD/ENTRYPOINT with /bin/bash
or similar to have a poke around to see what happened?
You can check previous logs of a pod by using --previous
flag:
On an event where you want to keep the container inside the pod alive then use the below code:
apiVersion: v1 kind: Pod metadata: name: ubuntu spec: containers: - name: ubuntu image: ubuntu:latest # Just spin & wait forever command: [ "/bin/bash", "-c", "--" ] args: [ "while true; do sleep 30; done;" ]
Ref
above the important lines are# Just spin & wait forever command: [ "/bin/bash", "-c", "--" ] args: [ "while true; do sleep 30; done;" ]