Ask Your Question
3

What is the bash command to monitor kubernetes namespace pods that are not in the Running/Completed status within a specific time frame?

asked 2022-02-16 11:00:00 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-07-31 22:00:00 +0000

djk gravatar image

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.

edit flag offensive delete link more

Your Answer

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

Add Answer


Question Tools

Stats

Asked: 2022-02-16 11:00:00 +0000

Seen: 11 times

Last updated: Jul 31 '21