简体   繁体   English

相当于 kubectl get pods 的 Python Kubernetes 客户端

[英]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.

相关问题 Python Kubernetes 客户端:相当于 kubectl get [custom-resource] - Python Kubernetes Client: equivalent of kubectl get [custom-resource] Kube.netes python 客户端相当于“kubectl wait --for”命令 - Kubernetes python client equivalent of "kubectl wait --for " command Python Kubernetes 客户端等效于 kubectl describe pod | grep 事件 - Python Kubernetes client equivalent of kubectl describe pod | grep Events 我需要使用 kubernetes python 客户端在 Kubernetes 集群中获取 Pod 的数量 - I need to get number of Pods in a Kubernetes Cluster with kubernetes python client kubernetes python客户端中的kubectl cp - kubectl cp in kubernetes python client 如何通过python客户端获取kubernetes中pod的日志和描述 - How to get log and describe of pods in kubernetes by python client 我需要使用 kubernetes python 客户端在 Kubernetes 集群中获取 Pod 的资源使用情况 - I need to get resource usage of Pods in a Kubernetes Cluster with kubernetes python client 使用Python Kubernetes客户端,一般如何复制`kubectl create -f`? - With Python Kubernetes client, how to replicate `kubectl create -f` generally? 使用与 K8s Python 客户端等效的 kubectl run 命令 - Using kubectl run command equivalent with K8s Python client 使用与 k8s python 客户端等效的 kubectl rollout restart - Using kubectl rollout restart equivalent with k8s python client
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM