[英]Python Kubernetes Client equivalent of kubectl get pods
I'm trying to use the Python Kubernetes Client to get the run-time of each container for all my pods.我正在尝试使用 Python Kubernetes 客户端来获取我所有 pod 的每个容器的运行时间。 Using the K8s CLI this information is available by using
kubectl describe pods
.使用 K8s CLI,可以使用
kubectl describe pods
获得此信息。
I can get the output for a single pod by using我可以通过使用获取单个 pod 的输出
api_response = api_instance.read_namespaced_pod(name='pod-name',namespace='namespace-name')
However, I need this information for all the pods.但是,我需要所有 pod 的这些信息。
What is the equivalent of kubectl get pods
for Python K8s library? Python K8s 库的
kubectl get pods
相当于什么? I'm thinking I can use this to create a list of pods and use the mentioned command above to loop through them by their pod-name and get the required information.我想我可以用它来创建一个 pod 列表,并使用上面提到的命令通过它们的 pod-name 循环它们并获取所需的信息。
从文档你可以试试这个api_response = api_instance.list_namespaced_pod(namespace='namespace-name')
You are right about using this command to get all pod names:使用此命令获取所有 pod 名称是正确的:
api_response = api_instance.read_namespaced_pod(name='pod-name',namespace='namespace-name')
But to get specifically the name of those, use something like this:但是要具体获取这些名称,请使用以下内容:
for i in api_response.items:
print("%s" %(i.metadata.name))
That should work for you :)那应该对你有用:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.