Sitemap

Kubernetes See Logs Of The Crashed Pod using Kubectl

2 min readMay 4, 2023

--

A loaded ship
Photo by Ian Taylor on Unsplash

Normally, we see only the current pod’s log when we look through the logs.

However, when our server crashes we actually want to see the last logs of the previous pod, because by default when Kubernetes will not be able to ping the defined health probe, it will restart the pod.

In order to see this, let’s first see what our current context is.

kubectl config get-contexts

I have 2 contexts and it also shows me in which context I am, if I want to go to another context I use

kubectl config use-context <preferred-context-name>

Then I need to find the name of my pod to see its last logs

kubectl get pods -n <preferred-namespace>| grep <term-to-search-for-your-pod>

We can actually see the pod that is keep restarting Now since we have the name of the pod let’s actually see the logs

kubectl logs -n <your-namespace> <your-copied-pod-name> --previous

If you get 10s of logs in your terminal, you did a great job 😄

Now go get that nasty bug 😂

--

--

Baris Balli
Baris Balli

Written by Baris Balli

Full stack developer. Polyglot

No responses yet