Interview Prep/Monitoring & Observability/Kubernetes Monitoring, Scale & Cloud

How do you detect restarts and OOMKills from kube-state-metrics?

BeginnerConceptKubernetes Monitoring, Scale & Cloud
Answer
# Containers restarting more than 3 times in 15 minutes
increase(kube_pod_container_status_restarts_total[15m]) > 3

# Last termination was an OOM kill (combine with restarts to catch recent ones)
kube_pod_container_status_last_terminated_reason{reason="OOMKilled"} == 1
  and on (namespace, pod, container)
increase(kube_pod_container_status_restarts_total[10m]) > 0

# Stuck waiting
kube_pod_container_status_waiting_reason{reason=~"CrashLoopBackOff|ImagePullBackOff"} == 1

last_terminated_reason keeps reporting the old reason until the next termination, so on its own it gives stale alerts; joining with a recent restart increase fixes that. The restarts_total counter resets when the pod is recreated, which increase() handles.

All Monitoring & Observability questions Roadmap: Monitoring & alerting

More on Kubernetes Monitoring, Scale & Cloud