【问题标题】:Python kubernetes client Get pod Ready state timepython kubernetes客户端获取pod就绪状态时间
【发布时间】:2020-04-10 15:13:36
【问题描述】:

我正在使用 python 客户端为 kubernetes 编写 python 脚本。

我要统计或计算PODReady状态时间。

In 30 Second pod Ready 或类似。

我现在打算用

'status': {
    'conditions': [
      {
        'last_probe_time': None,
        'last_transition_time': datetime.datetime(2019,
        12,
        17,
        13,
        14,
        58,
        tzinfo=tzutc()),
        'message': None,
        'reason': None,
        'status': 'True',
        'type': 'Initialized'
      },
      {
        'last_probe_time': None,
        'last_transition_time': datetime.datetime(2019,
        12,
        17,
        13,
        16,
        2,
        tzinfo=tzutc()),
        'message': None,
        'reason': None,
        'status': 'True',
        'type': 'Ready'
      },
      {
        'last_probe_time': None,
        'last_transition_time': datetime.datetime(2019,
        12,
        17,
        13,
        16,
        2,
        tzinfo=tzutc()),
        'message': None,
        'reason': None,
        'status': 'True',
        'type': 'ContainersReady'
      },
      {
        'last_probe_time': None,
        'last_transition_time': datetime.datetime(2019,
        12,
        17,
        13,
        14,
        58,
        tzinfo=tzutc()),
        'message': None,
        'reason': None,
        'status': 'True',
        'type': 'PodScheduled'
      }
    ]

但是期待直接可以从Pod初始化时间得到总Ready状态时间。

任何人都可以提出更好的方法。

非常感谢。

【问题讨论】:

    标签: python python-3.x kubernetes google-kubernetes-engine kubernetes-pod


    【解决方案1】:

    没有什么特别的,你已经有了你需要的数据。只需遍历列表,找到 Ready 和 Initialized 的两个 last_transition_times,然后减去。

    【讨论】:

    • 非常感谢您写的答案,真的很有帮助。和我想的一样。
    • 不,它们不是,您可以在您发布的内容中看到它们相隔 1 分 4 秒。
    • 是的,我明白了。谢谢。
    猜你喜欢
    • 2021-04-28
    • 2020-01-25
    • 2021-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-01
    • 1970-01-01
    • 2021-07-10
    相关资源
    最近更新 更多