Reputation: 139
we are looking to find the list of pods which is not in running state or having some issue. Though below command pull pods detail including good ones, however we are targeting only bad ones
'kubectl get pods -A'
Upvotes: 1
Views: 1018
Reputation: 1
Here is a script I use to find out which namespaces have problem pods and what the problems might be. I call the script notrunning
kubectl get po -A --no-headers |
awk '
BEGIN {
SUBSEP=" "
format = "%-20s %20s %5s\n"
printf format, "NAMESPACE", "STATUS", "COUNT"
}
!/Running/ {a[$1,$4]++}
END {
for (i in a) {split(i,t); printf format, t[1],t[2],a[i]}
}
' | sort
I get results similar to this:
$ notrunning
NAMESPACE STATUS COUNT
namespace-01 InvalidImageName 2
namespace-02 InvalidImageName 1
namespace-02 Init:ImagePullBackOff 1
namespace-03 CrashLoopBackOff 2
namespace-03 InvalidImageName 9
namespace-04 Init:ErrImagePull 1
Upvotes: 0
Reputation: 66
You can go about it the kubectl way like Samuel suggested, or a more bash-oriented way.
Here are a few I use and when I use them
kubectl get po -A | grep Pending
Looking for pods that have yet to schedule
kubectl get po -A | grep -v Running
Looking for pods in a state other than Running
kubectl get po -A -o wide | grep <IP>
Looking at all pods state for a given node
grep
is a pretty powerful CLI tool with regex support that can help filter the output of kubectl
commands.
Here's the man page for grep
http://linuxcommand.org/lc3_man_pages/grep1.html
Upvotes: 0
Reputation: 31
kubectl get pods --field-selector=status.phase=Failed
Or some better specification can be found here.
Upvotes: 3