【问题标题】:How can I get the number of running pods for an app using Python Kubernetes Package如何使用 Python Kubernetes 包获取应用程序的运行 pod 数量
【发布时间】:2019-05-08 03:02:54
【问题描述】:

我在 Kubernetes 上部署了一个应用程序。我想使用 Python 中的 kubernetes 包获取该部署的正在运行的 pod 的数量。任何线索表示赞赏。谢谢:)

【问题讨论】:

    标签: python docker kubernetes containers kubernetes-pod


    【解决方案1】:

    您是否考虑过阅读软件包中的文档?这是第一个样本!

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-06
      • 2021-06-13
      • 2019-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-23
      • 1970-01-01
      相关资源
      最近更新 更多