繁体   English   中英

Kubectl 获取 pod 中的文件创建时间

[英]Kubectl get file creation time in pod

如何使用kubectl execKubernetes API for python在 pod 内创建文件(纪元)的时间?

我需要这个时间来计算从现在到文件创建时间所经过的时间。

有什么建议么?

谢谢

我假设您在~/.kube/config下有一个kubeconfig文件

from kubernetes import client, config
from kubernetes.client.rest import ApiException
from pprint import pprint

config.load_kube_config()
v1 = client.CoreV1Api()

namespace = 'default'

try:
    api_response = v1.list_namespaced_pod(namespace)
    pprint(api_response.items[0].metadata.creation_timestamp)
except ApiException as e:
    print("Exception when calling CoreV1Api->list_namespaced_pod: %s\n" % e)

它返回 tzutc,您需要对其进行解析。

$ python3 get_pods.py
datetime.datetime(2020, 5, 25, 16, 2, 39, tzinfo=tzutc())

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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