Get status for readyness probe via kubernetes python API

2/22/2021

if I run

kubectl -n=mynamespace describe pod mypodname 

I get for example this 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 ?

I can get the POD infos, e.g. 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?

Any ideas?

Thank you!

-- feffe
api
kubernetes
python

1 Answer

2/22/2021

1) First of all - you are able to find all the methods here: CoreV1Api.md.

2) Part you are interested in:

[**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

4) your code taken from @Prafull Ladha from 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)
-- Vit
Source: StackOverflow