Complete list of pod statuses

9/2/2021

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.

-- Dave Pearce
kubectl
kubernetes

3 Answers

9/3/2021

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
-- pratik
Source: StackOverflow

9/3/2021

like comment in https://stackoverflow.com/questions/69035324/complete-list-of-pod-statuses#comment122014046_69035324 :

$ 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 https://github.com/kubernetes/kubernetes/blob/master/pkg/printers/internalversion/printers.go#L741 shows status based on pod.Status.Phase and will be changed.

-- Abirdcfly
Source: StackOverflow

9/3/2021

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.

-- Fariya Rahmat
Source: StackOverflow