简体   繁体   中英

I need to get number of Pods in a Kubernetes Cluster with kubernetes python client

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))

which gives me the output of

kubectl get po -A -o json 

and then finds the length. but i just want to do the output of

kubectl get po -A

In kubectl way:

kubectl get po -A --no-headers | wc -l

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM