Pods

6 min read

Answer questions about a set of Pods, as the API returns them, passed as a list or a PodList: names, IPs, phases, nodes, readiness, restarts, and why containers are waiting or failed (CrashLoopBackOff, OOMKilled, ImagePullBackOff, …).

Reference

FunctionDescription
hasCrashingPodReports whether any container is failing now: waiting or terminated with a failure reason (CrashLoopBackOff, OOMKilled, ImagePullBackOff, …), or not running after restarting before.
podByOrdinalReturns the pod whose name ends in -<ordinal>, as StatefulSet pods are named (web-0, web-1, …); nil when none does.
podContainerReasonsReturns the distinct reasons containers are waiting or terminated with, across all pods, in first-seen order.
podContainerStateReturns the state (Running, Waiting, Terminated) of a named container in the pod at ordinal; "" when either is not found.
podCountReturns the number of pods.
podCrashLoopDetectedReports whether any container in the pods is crash looping: waiting with reason CrashLoopBackOff, or terminated with a non-zero exit code after restarting before, as it shows between back-offs.
podCreateContainerErrorDetectedReports whether any container in the pods is waiting or terminated with reason, or last terminated with reason while not running, CreateContainerError.
podErrImagePullDetectedReports whether any container in the pods is waiting or terminated with reason, or last terminated with reason while not running, ErrImagePull.
podErrorDetectedReports whether any container in the pods is waiting or terminated with reason, or last terminated with reason while not running, Error.
podIPsReturns the pods’ IP addresses; pods without one yet are skipped.
podImagePullBackOffDetectedReports whether any container in the pods is waiting or terminated with reason, or last terminated with reason while not running, ImagePullBackOff.
podInvalidImageNameDetectedReports whether any container in the pods is waiting or terminated with reason, or last terminated with reason while not running, InvalidImageName.
podMaxRestartsReturns the highest restart count of any pod (the sum over its containers).
podNamesReturns the pods’ names, in order.
podNodesReturns the nodes the pods are scheduled on; pending pods are skipped.
podOOMKilledDetectedReports whether any container in the pods is waiting or terminated with reason, or last terminated with reason while not running, OOMKilled.
podPhasesReturns each pod’s phase, in order.
podPostStartHookErrorDetectedReports whether any container in the pods is waiting or terminated with reason, or last terminated with reason while not running, PostStartHookError.
podPreStartHookErrorDetectedReports whether any container in the pods is waiting or terminated with reason, or last terminated with reason while not running, PreStartHookError.
podRestartedWithinReports whether any container in the pods last terminated within window (“10m”, “1h”, “1d”), going by its last termination’s finishedAt.
podRunContainerErrorDetectedReports whether any container in the pods is waiting or terminated with reason, or last terminated with reason while not running, RunContainerError.
readyPodCountReturns the number of pods whose Ready condition is True.

Functions

hasCrashingPod

hasCrashingPod reports whether any container is failing now: waiting or terminated with a failure reason (CrashLoopBackOff, OOMKilled, ImagePullBackOff, …), or not running after restarting before. Init containers count. A container that is running again is not crashing, however often it restarted: restart counts only reset when the pod is replaced. For one that runs and crashes in turn, use podRestartedWithin.

{{ hasCrashingPod .pods }}  → true

podByOrdinal

podByOrdinal returns the pod whose name ends in -<ordinal>, as StatefulSet pods are named (web-0, web-1, …); nil when none does.

{{ (podByOrdinal .pods 0).status.podIP }}  → "10.0.0.1"

podContainerReasons

podContainerReasons returns the distinct reasons containers are waiting or terminated with, across all pods, in first-seen order.

{{ podContainerReasons .pods }}  → [ImagePullBackOff]

podContainerState

podContainerState returns the state (Running, Waiting, Terminated) of a named container in the pod at ordinal; "" when either is not found.

{{ podContainerState .pods 0 "app" }}  → "Running"

podCount

podCount returns the number of pods.

{{ podCount .pods }}  → 3

podCrashLoopDetected

podCrashLoopDetected reports whether any container in the pods is crash looping: waiting with reason CrashLoopBackOff, or terminated with a non-zero exit code after restarting before, as it shows between back-offs.

{{ podCrashLoopDetected .pods }}  → false

podCreateContainerErrorDetected

podCreateContainerErrorDetected reports whether any container in the pods is waiting or terminated with reason, or last terminated with reason while not running, CreateContainerError.

{{ podCreateContainerErrorDetected .pods }}  → false

podErrImagePullDetected

podErrImagePullDetected reports whether any container in the pods is waiting or terminated with reason, or last terminated with reason while not running, ErrImagePull.

{{ podErrImagePullDetected .pods }}  → false

podErrorDetected

podErrorDetected reports whether any container in the pods is waiting or terminated with reason, or last terminated with reason while not running, Error.

{{ podErrorDetected .pods }}  → false

podIPs

podIPs returns the pods’ IP addresses; pods without one yet are skipped.

{{ podIPs .pods }}  → [10.0.0.1 10.0.0.2]

podImagePullBackOffDetected

podImagePullBackOffDetected reports whether any container in the pods is waiting or terminated with reason, or last terminated with reason while not running, ImagePullBackOff.

{{ podImagePullBackOffDetected .pods }}  → true

podInvalidImageNameDetected

podInvalidImageNameDetected reports whether any container in the pods is waiting or terminated with reason, or last terminated with reason while not running, InvalidImageName.

{{ podInvalidImageNameDetected .pods }}  → false

podMaxRestarts

podMaxRestarts returns the highest restart count of any pod (the sum over its containers). 0 when there are no pods.

{{ podMaxRestarts .pods }}  → 1

podNames

podNames returns the pods’ names, in order.

{{ podNames .pods }}  → [web-0 web-1 web-2]
{{ join (podNames .pods) ", " }}  → "web-0, web-1, web-2"

podNodes

podNodes returns the nodes the pods are scheduled on; pending pods are skipped.

{{ podNodes .pods }}  → [node-1 node-2]

podOOMKilledDetected

podOOMKilledDetected reports whether any container in the pods is waiting or terminated with reason, or last terminated with reason while not running, OOMKilled.

{{ podOOMKilledDetected .pods }}  → false

podPhases

podPhases returns each pod’s phase, in order.

{{ podPhases .pods }}  → [Running Running Pending]

podPostStartHookErrorDetected

podPostStartHookErrorDetected reports whether any container in the pods is waiting or terminated with reason, or last terminated with reason while not running, PostStartHookError.

{{ podPostStartHookErrorDetected .pods }}  → false

podPreStartHookErrorDetected

podPreStartHookErrorDetected reports whether any container in the pods is waiting or terminated with reason, or last terminated with reason while not running, PreStartHookError.

{{ podPreStartHookErrorDetected .pods }}  → false

podRestartedWithin

podRestartedWithin reports whether any container in the pods last terminated within window (“10m”, “1h”, “1d”), going by its last termination’s finishedAt. It catches a container that runs for a while and crashes in turn, which looks healthy whenever it is running. An error when window is not a positive duration.

{{ podRestartedWithin .pods "10m" }}  → false

podRunContainerErrorDetected

podRunContainerErrorDetected reports whether any container in the pods is waiting or terminated with reason, or last terminated with reason while not running, RunContainerError.

{{ podRunContainerErrorDetected .pods }}  → false

readyPodCount

readyPodCount returns the number of pods whose Ready condition is True.

{{ readyPodCount .pods }}  → 2