本文介绍了我需要使用kubernetes python客户端获取Kubernetes集群中的Pod数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个代码来获取输出的Pod数量,但它在(ret_pod)中加载了太多不需要的数据,有没有更好的方法呢?
i have a code to get the number of Pods it give the output but it loads too many unwanted data in (ret_pod), is there a better way to do it?
from kubernetes import client , config
config.load_kube_config()
v1= client.CoreV1Api()
ret_pod = v1.list_pod_for_all_namespaces(watch=False)
print(len(ret_pod.items))
这给了我输出
kubectl get po -A -o json
,然后找到长度.但我只想做
and then finds the length. but i just want to do the output of
kubectl get po -A
推荐答案
以kubectl方式:
In kubectl way:
kubectl get po -A --no-headers | wc -l
这篇关于我需要使用kubernetes python客户端获取Kubernetes集群中的Pod数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!