SuVeRa
SuVeRa

Reputation: 2904

How to get correct status of a POD in Kubernetes using REST API

When a POD is terminating, how to get correct status Terminating using Kubernetes REST API. I am not able to figure it out. But kubectl always report correct status, and it also uses REST API to do that.

What magic am I missing in REST API ? does it call two different API's and accumulate status ?

Upvotes: 1

Views: 2161

Answers (1)

larsks
larsks

Reputation: 312700

You are not the first person to ask this question. The answer appears to be that kubectl inspects metadata.deletionTimestamp; if this exists (and, presumably, has a non-null value) then the pod is in Terminating state.

For example, for a running pod:

$ curl -s localhost:8001/api/v1/namespaces/mynamespace/pods/example | jq .metadata.deletionTimestamp
<empty output>

And then immediately after I kubectl delete the pod:

$ curl -s localhost:8001/api/v1/namespaces/mynamespace/pods/example | jq .metadata.deletionTimestamp
"2022-01-15T15:30:01Z"

Upvotes: 4

Related Questions