Sandeep kumar singh
Sandeep kumar singh

Reputation: 675

Troubleshooting why my pod is deleted in kubernete cluster

I have created a deployment which create a replica-set and this replica-set create pods. Now I found couple of time the pod is getting deleted (do not know why) and then the replica-set create a new pod.

I am unable to find the details for the previous pod. I need to know why the pod was deleted. Kubernetes server version 1.5.6. I am also not seeing anything in events. Whereas I can see some events in newer version of Kubernetes server.

Please let me know in case of any more information required.

I have given a simple use case here where I created a deployment and then deleted pod inside it:

[kubernate-test]$ kubectl run pod-deleted-reason-why --image=busybox  -- sh -c 'while true; do echo i am running, but not sure can fail any time;sleep 10;done'
deployment "pod-deleted-reason-why" created
[kubernate-test]$ kubectl get deployments |grep reason
pod-deleted-reason-why    1         1         1            1           32s
[kubernate-test]$ kubectl get replicaset |grep reason
pod-deleted-reason-why-59c9df7594    1         1         1         59s
[kubernate-test]$ kubectl get pods |grep reason
pod-deleted-reason-why-59c9df7594-nr8rs    1/1       Running            0          1m
[kubernate-test]$ kubectl delete pod pod-deleted-reason-why-59c9df7594-nr8rs
pod "pod-deleted-reason-why-59c9df7594-nr8rs" deleted
[kubernate-test]$ kubectl get pods |grep reason
pod-deleted-reason-why-59c9df7594-qpq5b    1/1       Running            0          1m

Here I manually deleted the pod - pod-deleted-reason-why-59c9df7594-nr8rs and replica-set has created a new pod - pod-deleted-reason-why-59c9df7594-qpq5b.

If the the pod was delete for some other reason (say node reboot) how could I know why the pod was deleted?

Upvotes: 2

Views: 4911

Answers (3)

pacuna
pacuna

Reputation: 2089

Describe pod is the way to go. I see this kind of thing everyday. Everytime I launch a new deployment I list the pods with kubectl get pods, then once I see the container creating message for the new pod I want to monitorize, I grab the id and then run kubectl describe pod [ID]. Even if the pod is replaced by a new one you can still see the exit error. You can probably also do kubectl logs [ID] to see more information.

Upvotes: 1

Jose Armesto
Jose Armesto

Reputation: 13739

You can display detailed information about a pod that no longer exists using

kubectl get pod --output=yaml

The output includes a lastState field with information about the last state of the pod.

 apiVersion: v1
 kind: Pod
 ...
     lastState:
       terminated:
         containerID: ...
         exitCode: 0
         finishedAt: ...
         message: ...
         ...

You can also use kubectl logs -p to fetch the logs for an instance of the container in a pod.

Upvotes: 0

Lev Kuznetsov
Lev Kuznetsov

Reputation: 3728

You can use kubectl describe pod ... to see more information

EDIT:

Correction, I didn't realize you were deleting things yourself, if you manually delete the pod I don't think you can get that information back. If a pod has existed and then someone deletes it the only way that happens is if you actually delete it. If it gets restarted for whatever reason the pod name stays the same.

Upvotes: 1

Related Questions