Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.