Home > Software engineering >  How to get correct status of a POD in Kubernetes using REST API
How to get correct status of a POD in Kubernetes using REST API

Time:01-16

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 ?

CodePudding user response:

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"
  •  Tags:  
  • Related