如果我跑
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 状态码这样的详细信息?
有什么想法吗?
谢谢!
答案 0 :(得分:0)
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) 您的代码取自 How to get log and describe of pods in kubernetes by python client
的 @Prafull Ladhafrom 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)