Kubectl get file creation time in pod
I assume you have a kubeconfig
file under ~/.kube/config
from kubernetes import client, configfrom kubernetes.client.rest import ApiExceptionfrom pprint import pprintconfig.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)
It returns tzutc, which you will need to parse.
$ python3 get_pods.pydatetime.datetime(2020, 5, 25, 16, 2, 39, tzinfo=tzutc())