Find failed pod from ALL namespaces with curl and JQ

Jbn1233
May 27, 2023

--

$ cat test.sh 
#!/bin/bash
curl --cert cert --key key -k -sS -XGET \
-H "Accept: application/json;as=Table;v=v1;g=meta.k8s.io,application/json;as=Table;v=v1beta1;g=meta.k8s.io,application/json" \
-H "User-Agent: kubectl/v1.23.16 (linux/amd64) kubernetes/60e5135" 'https://apiserver.test.th:6443/api/v1/pods' \
| jq -c '.rows[]|[.object.metadata.namespace,.cells[]]'| grep -Ev 'Completed|Running|Evicted|default|ContainerCreating'

$ ./test.sh
["xxxapi","xxxsiomclosesrgo-7455554fc4-jf9fr","0/1","CrashLoopBackOff",234,"20h","192.169.7.28","cnpwkpr78.test.th","<none>","<none>"]

First you have to extract cert/key from your KUBECONFIG .

I am no good with JQ, so I just use grep insead.

That’s all

--

--

Jbn1233
Jbn1233

Written by Jbn1233

Very short and simple notes for CKA/SRE and may not works on your environment | jbn1233@gmail.com | Bangkok, Thailand |

No responses yet