2

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
    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
    – mdaniel
    Mar 20, 2022 at 20:27

1 Answer 1

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.