简体   繁体   中英

Python kubernetes client Get pod Ready state time

I am writing python script for kubernetes using python client.

I want to count or calculate the POD Ready state time.

In 30 Second pod Ready or similar.

Right now i am planning to use

'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'
      }
    ]

But looking forward to directly can get total Ready state time from Pod initialised time.

can anybody suggest better way.

Thanks a lot.

There isn't something specific, you already have the data you need. Just go through the list and find the two last_transition_times for Ready and Initialized and then subtract.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM