jqkubernetes-apiserver

get pod creation status from k8s api json using jq


I am trying to use jq in the following to get a status on my pod "my pod":

curl '127.0.0.1:8080/api/v1/pods' | jq -r '.items[] | select(.metadata.name)'

This give me a ton of json, more specific how do you read json from k8s api - to get the status of a pod - running or not?

If I get items within a pod:

 curl '127.0.0.1:8080/api/v1/pods' | jq -r 'select(.items[].metadata.name="go-test-volume1").items[]

Sure enough I get a list, but which one to chose - there is a status.phase in all of them?

items

In the case of a status of CrashLoopBackOff:

 curl '127.0.0.1:8080/api/v1/pods' |
  jq -r '.items[] | select(.metadata.name == "my-pod").status.phase'

Will show it as Running?


Solution

  • This is what you need :

    curl '127.0.0.1:8080/api/v1/pods' |
      jq -r '.items[] | select(.metadata.name == "my-pod").status.phase'