How to get running pod status via Rest API

10/3/2018

Any idea how to get a POD status via Kubernetes REST API for a POD with known name? I can do it via kubectl by just typing "kubectl get pods --all-namespaces" since the output lists STATUS as a separate column but not sure which REST API to use to get the STATUS of a running pod. Thank you

-- Vladimir Smogitel
kubernetes

2 Answers

10/4/2018

You can just query the API server:

curl -k -X GET -H "Authorization: Bearer [REDACTED]" \
https://127.0.0.1:6443/api/v1/pods

If you want to get the status you can pipe them through something like jq:

curl -k -X GET -H "Authorization: Bearer [REDACTED]" \ 
https://127.0.0.1:6443/api/v1/pods \
| jq '.items[] | .metadata.name + " " + .status.phase'
-- Rico
Source: StackOverflow

10/4/2018

When not sure which REST API and the command is known, run the command as below with -v9 option. Note the kubectl supports only a subset of options in imperative way (get, delete, create etc), so it's better to get familiar with the REST API.

kubectl -v9 get pods

The above will output the REST API call. This can be modified appropriately and the output can piped to jq to get subset of the data.

-- Praveen Sripati
Source: StackOverflow