Kubernetes:如何使用 python 获取容器的状态和重新启动?

A_t*_*ser 7 python restart status kubernetes

我想使用python kubernetes获取容器状态并重新启动 pod 。我目前正在使用list_namespaced_pod来获取 pod 和容器状态,我将其解释为 pod 的状态。这可行,但远非理想的解决方案。我正在寻找能给我提供类似信息的东西kubectl -n $NAMESPACE get pods

Ric*_*ico 8

例如,您可以执行以下操作来获取所有 Pod 及其状态:

api_response = api_instance.list_namespaced_pod(namespace, pretty=pretty, timeout_seconds=timeout_seconds, watch=watch)

for i in api_response.items:
    print(i.metadata.name + " " + i.status.phase)
Run Code Online (Sandbox Code Playgroud)