user1403806
user1403806

Reputation: 79

How to find logs for pods created and deleted within a short period of time

When k8s job keeps recreating pods within 10 seconds, what is the best way to get the related logs and find out the root cause? I tried to use

kubectl logs <pod> -n <namespace>

and always got Error from server (NotFound): pods "XXXX" not found as it already got deleted and a new pod got created in the meantime.

Upvotes: 1

Views: 1137

Answers (1)

Adiii
Adiii

Reputation: 59926

If the pod "restarting/crashloop" then you can get logs from the previous run.

kubectl logs -n <namespace> <pod> --previous

This will show you the logs of the last run of the pod before it crashed. It is a handy feature in case you want to figure out why the pod crashed in the first place.

For the long term you should consider some logging solution as the pod should be treated as a disposable object and should not rely on this.

One of best tool that I used so far without any issue Kubernetes Log collection using datadog

Upvotes: 1

Related Questions