【问题标题】:Get status for readyness probe via kubernetes python API在 kubernetes python API 中获取就绪探针的状态
【发布时间】:2021-05-24 14:39:45
【问题描述】:

如果我跑

kubectl -n=mynamespace describe pod mypodname 

我得到例如这个输出:

  Type     Reason     Age                      From                  Message
  ----     ------     ----                     ----                  -------
  Warning  Unhealthy  43s (x30458 over 3d17h)  kubelet, myhostname  Readiness probe failed: HTTP probe failed with statuscode: 404

现在我如何通过 python 库https://github.com/kubernetes-client/python 获得这个?

我可以获取 POD 信息,例如使用 list_pod_for_all_namespaces 并获取一个 POD 对象https://github.com/kubernetes-client/python/blob/6d64cf67d38337a6fdde1908bdadf047b7118731/kubernetes/docs/V1Pod.md

但这仅显示(在 podobject.status.conditions 属性中)容器尚未准备好,但我没有得到像上面的 404 状态码这样的详细信息?

有什么想法吗?

谢谢!

【问题讨论】:

    标签: python api kubernetes


    【解决方案1】:

    1) 首先 - 您可以在这里找到所有方法:CoreV1Api.md

    2)您感兴趣的部分:

    [**read_namespaced_pod**](CoreV1Api.md#read_namespaced_pod) | **GET** /api/v1/namespaces/{namespace}/pods/{name} | 
    [**read_namespaced_pod_log**](CoreV1Api.md#read_namespaced_pod_log) | **GET** /api/v1/namespaces/{namespace}/pods/{name}/log | 
    [**read_namespaced_pod_status**](CoreV1Api.md#read_namespaced_pod_status) | **GET** /api/v1/namespaces/{namespace}/pods/{name}/status | 
    [**read_namespaced_pod_template**](CoreV1Api.md#read_namespaced_pod_template) | **GET** /api/v1/namespaces/{namespace}/podtemplates/{name} | 
    

    3)你正确的方法是read_namespaced_pod

    4)您的代码取自@Prafull Ladha,来自How to get log and describe of pods in kubernetes by python client

    from kubernetes.client.rest import ApiException
    from kubernetes import client, config
    
    config.load_kube_config()
    pod_name = "counter"
    try:
        api_instance = client.CoreV1Api()
        api_response = api_instance.read_namespaced_pod(name=pod_name, namespace='default')
        print(api_response)
    

    【讨论】:

    • 谢谢。对于链接。这有助于我访问容器日志......我也在寻找。但是,我上面提到的 (list_pod_for_all_namespaces) 和“你的”read_namespaced_pod) 方法都返回一个 V1Pof 对象的列表或单个 V1Pof 对象。因此,信息与我已经拥有的信息相同。我无法得到我正在寻找的就绪探测错误。我假设我需要使用事件 api 左右......
    猜你喜欢
    • 2019-07-22
    • 2021-05-24
    • 2021-12-03
    • 1970-01-01
    • 2020-04-10
    • 1970-01-01
    • 1970-01-01
    • 2020-05-11
    • 2019-07-01
    相关资源
    最近更新 更多