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.
Asked
Active
Viewed 9,559 times
2 Answers
18
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!

Stepan Maksimchuk
- 926
- 1
- 6
- 11
-
Yes, This solution is working perfectly. Thank you so much. – setiabb Dec 31 '18 at 08:57
0
The status info is a sub-struct of the pod as a whole so you use the normal getter (clientset.CoreV1() etc) and then look in the .Status
struct.

coderanger
- 52,400
- 4
- 52
- 75
-
Do you mean something like this? "clientset.CoreV1().Pods(namespace).Get("podname", metav1.GetOptions{}).Status" – setiabb Dec 19 '18 at 20:19