Kubernetes inspecting a stopped Pod

10/2/2019

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?

-- Jethro
docker
kubernetes

1 Answer

10/2/2019

You can check previous logs of a pod by using --previous flag:

  1. kubectl logs my-pod --previous ref
  2. kubectl logs my-pod -c my-container --previous ref

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;" ]

-- garlicFrancium
Source: StackOverflow