Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get status of a pod in kubernetes using go-client

I am trying to delete a pod in my kubernetes cluster, then check its status to see how long does it take for the pod to get down, and up again. I could not find any helpful example for the second part which is getting a specific pod status using go-client. Any help is appreciated.

like image 749
setiabb Avatar asked Dec 17 '22 19:12

setiabb


1 Answers

You can use Get function to get specific pod information (below examples are getting whole Status struct):

pod, _ := clientset.CoreV1().Pods("kubernetes").Get(pod.Name, metav1.GetOptions{})
fmt.Println(pod.Status)

Also, you can use List function to get all pods in the particular namespace and then range them:

pods, _ := clientset.CoreV1().Pods("kubernetes").List(metav1.ListOptions{FieldSelector: "metadata.name=kubernetes"})
for _, pod := range pods.Items {
    fmt.Println(pod.Name, pod.Status)
}

Hope this helps!

like image 107
Stepan Maksimchuk Avatar answered Jan 04 '23 01:01

Stepan Maksimchuk