1

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
  • 3,029
  • 3
  • 27
  • 56

1 Answers1

1

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
  • 2,013
  • 14
  • 23
  • Thanks, this is very useful! Bringing back an identical pod with a sleep command works well, but when there are several ConfigMaps, Volumes, Secrets etc... it can be a lot of work to manually recreate it as it was. Am just experimenting with parsing the manifest from `kubectl get pod myPod -o yaml` into something that can be spun up again using your sleep command, eg `kubectl apply -f myPodResurrected.yaml`. – Jethro Oct 02 '19 at 15:21
  • this might be helpful https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell – garlicFrancium Oct 02 '19 at 16:35