An alert rule is kube_pod_container_status_restarts_total > 3. It has been firing for six weeks on a pod that restarted four times during a deploy in July. What is wrong?
- The metric is a counter; the rule should alert on
increase(kube_pod_container_status_restarts_total[1h]) > 3so it fires on new restarts, not on history. Counters only go up; thresholds on the raw value describe the past forever. - kube-state-metrics is stale and needs a restart. The value is correct; the interpretation is wrong.
- The threshold is too low; use 30. Any raw threshold eventually sticks; the fix is the rate/increase function.
- Alerts should never be on restarts. Restart loops are a legitimate symptom; the rule just has to be shaped for a counter.
The restart metric is a counter that only goes up; alert on increase() over a window instead of the raw value.
Counter versus gauge is the most common alert bug on Kubernetes. increase() or rate() over a window turns a cumulative count into "how many recently", which is what a page should mean. Pair it with a for: duration so a single restart during a rollout does not page.
Tuning the threshold. Any raw threshold on a counter sticks forever; only rate() or increase() over a window turns it into 'how many recently'.