How to list Kubernetes recently deleted pods?

后端 未结 8 748
隐瞒了意图╮
隐瞒了意图╮ 2020-12-14 14:35

Is there a way to get some details about Kubernetes pod that was deleted (stopped, replaced by new version).

I am investigating bug. I have logs with my pod name. Th

相关标签:
8条回答
  • 2020-12-14 15:16
    kubectl get pods -a    
    

    you will get the list of running pods and the terminated pods in case you are searching for this

    0 讨论(0)
  • 2020-12-14 15:21

    There is a way to find out why pods were deleted and who deleted them. The only way to find out something is to set the ttl for k8s to be greater than the default 1h and search through the events:

    kubectl get event -o custom-columns=NAME:.metadata.name | cut -d "." -f1

    0 讨论(0)
  • 2020-12-14 15:22

    as far as i know you may not get the pod details once the pod is deleted. can i know what is the usecase?

    example:

    1. if a pod created using - kubectl run busybox-test-pod-status --image=busybox --restart=Never -- /bin/false you will have a pod with status termiated:error
    2. if a pod is created using - kubectl run busybox-test-pod-status --image=busybox --restart=Never -- /bin/true you will have pod with status terminated:Complted
    3. if container in a pods restarts: the pod will be alive and you can get the logs of previous container (only the previous container) using kubectl logs --container < container_name > --previous=true < pod_name >
    4. if you doing an upgrade of you app and you are creating pods using deployments. if the update deployment "say a new image". pod will be terminated and new pod will be created. you can get the pod details from depoyment yaml. if you want to get details of previous pod you have see "spec" section of previous deployment yaml
    0 讨论(0)
  • 2020-12-14 15:22

    You can try kubectl logs --previous to list the logs of a previously stopped pod

    http://kubernetes.io/docs/user-guide/kubectl/kubectl_logs/

    You may also want to check out these debugging tips http://kubernetes.io/docs/user-guide/debugging-pods-and-replication-controllers/

    0 讨论(0)
  • 2020-12-14 15:26

    There is this flag:

    -a, --show-all=false: When printing, show all resources (default hide terminated pods.)

    But this may not help in all cases of old pods.

    0 讨论(0)
  • 2020-12-14 15:30

    If your container has previously crashed, you can access the previous container’s crash log with:

    kubectl logs --previous ${POD_NAME} ${CONTAINER_NAME}

    0 讨论(0)
提交回复
热议问题