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.
More on Kubernetes Monitoring, Scale & Cloud
What is kube-prometheus-stack and what does it install?BeginnerWhat CRDs does the Prometheus Operator provide?IntermediateHow does the Prometheus Operator decide which ServiceMonitors to load?IntermediateWhich cAdvisor container memory metric should you watch, and why?IntermediateHow do metrics-server and the custom/external metrics APIs relate to HPA?IntermediateWhich kube-state-metrics metrics do you use most?Beginner