我在Kubernetes上部署了一个应用程序。我想使用Python中的kubernetes包来获取该部署的运行Pod的数量。任何线索表示赞赏。谢谢:)
答案 0 :(得分:0)
您是否考虑过从软件包中阅读文档?这是第一个样品!
https://github.com/kubernetes-client/python
from kubernetes import client, config
# Configs can be set in Configuration class directly or using helper utility
config.load_kube_config()
v1 = client.CoreV1Api()
print("Listing pods with their IPs:")
ret = v1.list_pod_for_all_namespaces(watch=False)
for i in ret.items:
print("%s\t%s\t%s" % (i.status.pod_ip, i.metadata.namespace, i.metadata.name))
https://github.com/mnubo/kubernetes-py
from kubernetes import K8sPod
pod = K8sPod(config=cfg_token, name='redis')
pod.list()