简体   繁体   English

通过 kubernetes python API 获取就绪探针的状态

[英]Get status for readyness probe via kubernetes python API

if I run如果我跑

kubectl -n=mynamespace describe pod mypodname 

I get for example this output:例如,我得到这个 output:

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

Now how can I get this via the python library https://github.com/kubernetes-client/python ?现在我怎样才能通过 python 库https://github.com/kubernetes-client/python获得这个?

I can get the POD infos, eg using list_pod_for_all_namespaces and get a POD object https://github.com/kubernetes-client/python/blob/6d64cf67d38337a6fdde1908bdadf047b7118731/kubernetes/docs/V1Pod.md I can get the POD infos, eg using list_pod_for_all_namespaces and get a POD object https://github.com/kubernetes-client/python/blob/6d64cf67d38337a6fdde1908bdadf047b7118731/kubernetes/docs/V1Pod.md

but this does only show me (in the podobject.status.conditions property) that the containers are not ready but I get no detailled info like the 404 statuscode above?但这只会告诉我(在 podobject.status.conditions 属性中)容器尚未准备好,但我没有得到像上面的 404 状态码这样的详细信息?

Any ideas?有任何想法吗?

Thank you!谢谢!

1) First of all - you are able to find all the methods here: CoreV1Api.md . 1)首先 - 你可以在这里找到所有的方法: CoreV1Api.md

2) Part you are interested in: 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) Your right method is read_namespaced_pod 3)你正确的方法是read_namespaced_pod

4) your code taken from @Prafull Ladha from How to get log and describe of pods in kubernetes by python client 4)你的代码取自 @Prafull Ladha 来自How to get log and describe of pods in kubernetes by python 客户端

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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