One way to monitor Kubernetes namespace pods that are not in the Running/Completed status within a specific time frame is by using the following bash command:
kubectl get pods --namespace=<namespace> --field-selector=status.phase!=Running,status.phase!=Succeeded --selector=<label-selector> --sort-by='{.metadata.creationTimestamp}' | awk '{print $1,$2,$3,$4,$5,$6,$7; system("kubectl describe pod --namespace=<namespace> " $1" | grep -A 2 -i 'State:'")}'
This command will list all the pods in the specified namespace that are not running or completed, sorted by their creation timestamp. The <label-selector>
can be used to filter the pods further, if needed.
This command also uses awk
and kubectl describe
to get additional details about the pod's state, such as the reason for failure or the current phase it is in.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-02-16 11:00:00 +0000
Seen: 11 times
Last updated: Jul 31 '21