【问题标题】:How to get correct status of a POD in Kubernetes using REST API如何使用 REST API 在 Kubernetes 中获取 POD 的正确状态
【发布时间】:2022-01-15 23:31:54
【问题描述】:

当 POD 正在终止时,如何使用 Kubernetes REST API 获得正确的状态Terminating。我无法弄清楚。 但是 kubectl 总是报告正确的状态,并且它也使用 REST API 来做到这一点。

我在 REST API 中缺少什么魔力?它会调用两个不同的 API 并累积状态吗?

【问题讨论】:

    标签: kubernetes


    【解决方案1】:

    你不是first person to ask this question。答案似乎是kubectl 检查metadata.deletionTimestamp;如果存在(并且可能具有非空值),则 pod 处于 Terminating 状态。

    例如,对于正在运行的 pod:

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

    然后在我kubectl delete pod 之后:

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

    【讨论】:

    • 您提供的链接也包含 GO 代码,这非常有用。谢谢!!
    猜你喜欢
    • 2019-03-09
    • 2019-05-20
    • 1970-01-01
    • 2020-11-22
    • 1970-01-01
    • 2022-01-27
    • 1970-01-01
    • 2019-02-22
    • 2019-12-09
    相关资源
    最近更新 更多