英文:
How do i programatically determine whether a pod is in crashloopbackoff
问题
有没有办法通过编程确定一个 pod 是否处于 crashloopbackoff 状态?
我尝试了以下代码:
pods, err := client.CoreV1().Pods(namespace).List(context.TODO(), metav1.ListOptions{})
if err != nil {
return err
}
for _, item := range pods.Items {
log.Printf("found pod %v with state %v reason %v and phase %v that started at %v",
item.Name, item.Status.Message, item.Status.Reason, item.Status.Phase, item.CreationTimestamp.Time)
}
然而,这只会打印出状态和原因为空,但会打印出阶段信息。
英文:
Is there a way to determine programatically if a pod is in crashloopbackoff?
I tried the following
pods,err := client.CoreV1().Pods(namespace).List(context.TODO(), metav1.ListOptions{})
if err != nil {
return err
}
for _, item := range pods.Items {
log.Printf("found pod %v with state %v reason %v and phase %v that started at %v",
item.Name, item.Status.Message, item.Status.Reason, item.Status.Phase, item.CreationTimestamp.Time)
}
However this just prints blank for state and reason, tough it prints the phase.
答案1
得分: 2
为了澄清,我正在发布一个社区维基回答。
>它隐藏在ContainerStateWaiting.Reason
中:
kubectl get po -o jsonpath='{.items[*].status.containerStatuses[*].state.waiting.reason}'
>需要注意的是,它只会间歇性地显示在那里,因为它是容器的间歇性状态;也许更加程序化的方法是检查restartCount
和Error
状态。
另请参阅此存储库。
英文:
To clarify I am posting a community wiki answer.
>It's hiding in ContainerStateWaiting.Reason
:
kubectl get po -o jsonpath='{.items[*].status.containerStatuses[*].state.waiting.reason}'
>although be aware that it only intermittently shows up there, since it is an intermittent state of the container; perhaps a more programmatic approach is to examine the restartCount
and the Error
state
See also this repository.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论