When you run "kubectl get pods -A -o wide" you get a list of pods and a STATUS column.

Where can I get a list of the possible status options?

What I trying to do is generate a list of statuses and how many pods are in each status. If I had a list of the possible status states I could do what I need.

Thanks.

2

4 Answers

kubectl summarizes the status of pods as follows:

  1. It is the pod.status.phase (e.g. Running)
  2. If the pod.status.reason is not empty, then it is used (e.g. Evicted)
  3. If the pod.status.conditions contains a type PodScheduled with reason WaitingForGates, then it is set to SchedulingGated
  4. Then the pod.status.initContainerStatuses are taken into account (if there are any)
  5. Then the pod.status.containerStatuses are taken into account where it is set to a Waiting, Terminated or Completed state. The Completed state is mapped to Running or NotReady if at least one container in a pod is running.
  6. Lastly, the pod might be deleted (e.g. Terminating) or deleted and unreachable (e.g. Unknown)

I just tried to summarize the code in .

Values in pod status API

Pod Phases (pod.status.phase) are:

  • Pending
  • Running
  • Succeeded
  • Failed
  • Unknown (deprecated since v1.21)

Pod Condition Types (pod.status.conditions.type) are:

  • PodScheduled
  • Ready
  • Initialized
  • ContainersReady
  • DisruptionTarget

if you want also result on container basics, you try this command

kubectl get pods -A -o wide --no-headers | cut -b 85-108 | sort | uniq -c 

if the output looks like

 2 0/1 CrashLoopBackOff 1 0/3 Pending 260 1/1 Running 4 2/2 Running 

like comment in Complete list of pod statuses :

$ kubectl get pod -A --no-headers |awk '{arr[$4]++}END{for (a in arr) print a, arr[a]}' Evicted 1 Running 121 CrashLoopBackOff 4 Completed 5 Pending 1 

This command will shows how many pod are currently in what state.

But how to get the possible values of all the states?

In my view, there is no api or command to get it.
This status: "The aggregate status of the containers in this pod." source code can be find in shows status based on pod.Status.Phase and will be changed.

A phase of a Pod is a simple, high-level summary of where the Pod is in its Lifecycle.

The phase is not intended to be a comprehensive rollup of observations of Container or Pod state, nor is it intended to be a comprehensive state machine. Here are the possible values for phase:

Pending The Pod has been accepted by the Kubernetes system, but one or more of the Container images has not been created. This includes time before being scheduled as well as time spent downloading images over the network, which could take a while.

Running The Pod has been bound to a node, and all the Containers have been created. At least one Container is still running, or is working on starting or restarting.

Succeeded All Containers in the Pod have terminated in success, and will not be restarted.

Failed All Containers in the Pod have terminated, and at least one Container has terminated in failure. That is, the Container either exited with non-zero status or was terminated by the system.

Unknown For some reason the state of the Pod could not be obtained, typically due to an error in communicating with the host of the Pod.

If you are interested in detailed arrays with Pod conditions, I suggest looking at Pod Lifecycle from Kubernetes documentation and inspect source code for remaining information.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.