There are a couple of things that you can use to get alerted on OOM and other issues, one is certainly container_oom_events_total which is provided by cadvisor but it has an issue when using it alongside Kubernetes see open GH issue here. You could also use kube_pod_container_status_last_terminated_reason{reason="OOMKilled"} but then again it's not entirely accurate because it doesn't clear until a container is terminated for a different reason meaning it might be running and instead return such data. Last but not least you could use node_vmstat_oom_kill which as of today is working as expected, the downside of this one is that it works at node_level meaning it will not trigger only for a specific pod but for any pod having OOM issues (if you ask me this is good enough for alerting, regardless of it is a specific workload or not you want to get alerted when OOM its happening).

But if you need to use something that will give you the specific workload you could use a group_left between the kube_pod_container_status_restarts_total and the kube_pod_container_status_last_terminated_reason which should give you the restarts caused by OOM per workload... Something like the query below

sum by (namespace, pod) (kube_pod_container_status_restarts_total) * on(namespace, pod) group_left(reason) kube_pod_container_status_last_terminated_reason{reason="OOMKilled"}
Answer from r4cc00n on Stack Overflow
Top answer
1 of 3
4

There are a couple of things that you can use to get alerted on OOM and other issues, one is certainly container_oom_events_total which is provided by cadvisor but it has an issue when using it alongside Kubernetes see open GH issue here. You could also use kube_pod_container_status_last_terminated_reason{reason="OOMKilled"} but then again it's not entirely accurate because it doesn't clear until a container is terminated for a different reason meaning it might be running and instead return such data. Last but not least you could use node_vmstat_oom_kill which as of today is working as expected, the downside of this one is that it works at node_level meaning it will not trigger only for a specific pod but for any pod having OOM issues (if you ask me this is good enough for alerting, regardless of it is a specific workload or not you want to get alerted when OOM its happening).

But if you need to use something that will give you the specific workload you could use a group_left between the kube_pod_container_status_restarts_total and the kube_pod_container_status_last_terminated_reason which should give you the restarts caused by OOM per workload... Something like the query below

sum by (namespace, pod) (kube_pod_container_status_restarts_total) * on(namespace, pod) group_left(reason) kube_pod_container_status_last_terminated_reason{reason="OOMKilled"}
2 of 3
3

As i know there is two metrics which allow you to monitor OOM. The first one is used for tracking OOMKilled status of your main process/pid. If it breach the limit pod will be restarted with this status.

kube_pod_container_status_last_terminated_reason{reason="OOMKilled"}

And the second one for gathering total count of OOM events inside the container. So every time some child process or other process will breach the RAM limit they will be just killed and metric counter increased. But the container will be working as usual.

container_oom_events_total
🌐
Reddit
reddit.com › r/kubernetes › help me finding pods killed by oom
r/kubernetes on Reddit: Help me finding pods killed by OOM
September 20, 2024 -

Hello. Recently we are seeing many events like below. Cluster is running in version 1.27.16.
How can we find which POD has been killed? Without that information I don't really know on which pod we need to increase memory limits.
Sometimes in this place where we see "Java" is something different, so it's difficult for me sometimes to find "gulity" pod, as it's not the POD name but process name if I am not wrong.
Thanks in advance!

Warning  OOMKilling  43m    kernel-monitor  Memory cgroup out of memory: Killed process 662566 (java) total-vm:16311612kB, anon-rss:6252312kB, file-rss:18048kB, shmem-rss:0kB, UID:1001 pgtables:13056kB oom_score_adj:873

🌐
Netice9
netice9.com › blog › guide-to-oomkill-alerting-in-kubernetes-clusters
Guide to OOMKill Alerting in Kubernetes Clusters · NetIce9
November 23, 2020 - Having a hard time finding an existing solution meant only one thing: I will have to write my own. A cursory look at Docker’s events delivered everything I needed. There is an event called oom. Docker emits this event every time the OOMKiller process gets active in the container.
🌐
Reddit
reddit.com › r/prometheusmonitoring › prometheus is getting killed oomkilled
r/PrometheusMonitoring on Reddit: Prometheus is getting killed OOMKilled
October 10, 2022 - My Prometheus instance is consuming a lot of memory over 13Gi, the node has a max 16Gb, so it's getting killed by k8s, how can I configure or should…
🌐
Patrick Easters
patrick.easte.rs › posts › taking a whack at custom prometheus alerting
Taking a whack at custom Prometheus alerting | Patrick Easters
May 12, 2022 - We’ll configure a Prometheus alert to detect our out-of-memory conditions and then fire a webhook to a Raspberry Pi when containers are killed. To get started, we’ll need a Prometheus instance configured to scrape kube-state-metrics, which is where we’ll get metrics for container status.
🌐
GitHub
github.com › xing › kubernetes-oom-event-generator › blob › master › README.md
kubernetes-oom-event-generator/README.md at master · xing/kubernetes-oom-event-generator
When kube-state-metrics is deployed in the cluster and a Prometheus installation is scraping the metrics, you can alert on OOM-killed pods using the prometheus alert manager. Example alert: alert: ComponentOutOfMemory expr: sum_over_time(ku...
Author: xing
🌐
Blog
songrgg.github.io › operation › how-to-alert-for-Pod-Restart-OOMKilled-in-Kubernetes
How to alert for Pod Restart & OOMKilled in Kubernetes - Blog | Songrgg
July 14, 2021 - In Prometheus, we can use kube_pod_container_status_last_terminated_reason{reason="OOMKilled"} to filter the OOMKilled metrics and build the graph. However, as Guide to OOMKill Alerting in Kubernetes Clusters said, this metric will not be emitted ...
Top answer
1 of 2
3

Here are most likely reasons of prometheus eating memory:

  1. Overwhelming number of timeseries. Considering background this is most plausable. In prometheus datapoints are taking not much memory compared to unique timeseries. I couldn't find link now but AFAIR one datapoint takes around 4 bytes while timeseries w/o any datapoints takes around 1Kb. So having timeseries even w/o any datapoints will take space and might take memory. You can rule out this reason by comparing number of timeseries in prod and stage: count({__name__=~".+"}). If there are significantly more timeseries in prod you'll have to figure out why and probably further reduce the number.
  2. PromQL queries that load to much data into memory. If you have queries requesting long time period or huge amount of timeseries it could also be a reason since prometheus tries to load requested data into memory. Since you have OOM constantly reproducing you can test this assumption by blocking all queries to prometheus and see if it still hits OOM. It may be worth to look at query log too.
  3. Not enough memory on node. It could be just that other containers consume memory on node and prometheus is killed because it has lower QoS. Just make sure prometheus falls into guaranteed QoS.
2 of 2
1

The cause of my issue was a broken keycloak deployment in the keycloak namespace. An old keycloak setup was creating an high number of replicasets (around 36000), which caused the high cardinality for the replicaset-related queries in Prom.

The issue was not in staging since staging didn't mirror that configuration completely.

I had already tried the following relabeling to kube-state-metrics, dropping the queries before ingestion:

   - regex: '(kube_replicaset_status_observed_generation|kube_replicaset_status_replicas|kube_replicaset_labels|kube_replicaset_created|kube_replicaset_annotations|kube_replicaset_status_ready_replicas|kube_replicaset_spec_replicas|kube_replicaset_owner|kube_replicaset_status_fully_labeled_replicas|kube_replicaset_metadata_generation)'
    action: drop
    sourceLabels: [__name__]

but it proved to be too conservative. After adding:

- regex: 'keycloak'
action: drop
sourceLabels: [namespace]

my instance became stable again.

🌐
OneUptime
oneuptime.com › home › blog › how to troubleshoot oomkilled pods on aks and configure proper memory limits
How to Troubleshoot OOMKilled Pods on AKS and Configure Proper Memory Limits
February 16, 2026 - Set up alerts before pods get OOM killed. # prometheus-alert.yaml # Alert when memory usage exceeds 85% of the limit apiVersion: monitoring.coreos.com/v1 kind: PrometheusRule metadata: name: memory-alerts namespace: monitoring spec: groups: ...
Find elsewhere
Top answer
1 of 2
5

Periodically I see the container Status: terminated - OOMKilled (exit code: 137)

But it's scheduled to the node with plenty of memory

As you may have already seen it's evident you are hitting more than the 1GB configured. The answer probably lies in how you are using Prometheus and what usage limits you are hitting for 1GB. Some of the things you can look at:

  • Number of Time Series
  • Average Labels Per Time Series
  • Number of Unique Label Pairs
  • Scrape Interval (s)
  • Bytes per Sample

You can find a memory calculator for the usage above 👉 here.

✌️

2 of 2
1

The 1Gi memory limit for Prometheus pod is quite low for Kubernetes monitoring, where millions of metrics are scraped from thousands of targets (pods, nodes, endpoints, etc.).

The recommendation is to raise the memory limit for Prometheus pod until it stops crashing with out of memory error.

It is recommended setting up monitoring for the Prometheus itself - it exports own metrics at http://prometheus-host:9090/metrics url - see, for example, http://demo.robustperception.io:9090/metrics .

Prometheus memory usage can be decreased in the following ways:

  • To increase scrape_interval in Prometheus configs, so it scrapes targets less frequently. This reduces Prometheus memory usage, since Prometheus stores recently scraped metrics in memory for up to 2 hours.
  • To filter out unneeded scrape targets via relabel_configs. See https://www.robustperception.io/life-of-a-label .
  • To filter out unneeded metrics via metric_relabel_configs. See https://www.robustperception.io/life-of-a-label .

P.S. There are alternative Prometheus-like solutions, which can use lower amounts of memory when scraping the same set of targets. See, for example, vmagent and VictoriaMetrics.

🌐
GitHub
github.com › prometheus › prometheus › discussions › 9936
Prometheus getting OOM killed · prometheus/prometheus · Discussion #9936
November 29, 2021 - To further understand, I dropped all the metrics from the scrape targets (in metric_relabel_configs -> keep only for an unavailable label value). # Head series reduced to 15K (all internal to Prometheus). Screenshots below. Memory usage was still high at 45G.
Author: prometheus
🌐
Seifrajhi
seifrajhi.github.io › home › blog › prometheus restart troubles: managing memory overload 🧠
Prometheus Restart Troubles: Managing Memory Overload 🧠 - Blog by Saifeddine Rajhi
October 29, 2024 - Prometheus is indeed running, but it got terminated due to an OOMKill — running out of memory. It seems Prometheus is in the midst of recovering from the Write Ahead Log (WAL), which might be causing the memory spike.
🌐
GitHub
github.com › m-lab › prometheus-support › issues › 213
Add alerts for containers terminated by OOM (or other reasons) · Issue #213 · m-lab/prometheus-support
April 3, 2018 - Recently we found that the node exporter in scraper was being OOMKilled by k8s. However, this was not alerted, we just happen to stumble across it. m-lab/scraper#274 Ideally, prometheus should have a general alert checking for this condi...
Author: m-lab
🌐
GitHub
github.com › prometheus › prometheus › issues › 14195
Prometheus Memory Peaks OOMKilled · Issue #14195 · prometheus/prometheus
June 3, 2024 - No memory peaks and dealing with the resource limits, i.e. sequentially performings tasks slower to avoid memory peaks. Memory peaks nearly doubling the average memory foot print resulting in OOMKilled prometheus pod.
Author: prometheus
🌐
Stack Overflow
stackoverflow.com › questions › 76008209 › prometheus-oomkilled-despite-6gi-limits-how-to-debug
kubernetes - Prometheus OOMkilled despite 6Gi limits; how to debug - Stack Overflow
April 13, 2023 - I have two environments, staging and prod. In staging, my prometheus runs smoothly. In prod it has started crashing with OOMKilled errors roughly every 4 minutes.
🌐
GitHub
github.com › prometheus › prometheus › issues › 9849
Prometheus getting OOM killed · Issue #9849 · prometheus/prometheus
November 23, 2021 - Dismiss alert · {{ message }} prometheus / prometheus Public · Notifications · You must be signed in to change notification settings · Fork 10k · Star 61.5k · New issueCopy link · New issueCopy link · Closed · Closed · Prometheus getting OOM killed#9849 ·
Author: prometheus
🌐
Atmosly
atmosly.com › blog › how-to-fix-kubernetes-oomkilled-errors-2025
Kubernetes OOMKilled: Exit Code 137 Fixed (2026)
December 10, 2025 - resources: requests: memory: 512Mi # Guaranteed allocation (for scheduling) limits: memory: 768Mi # Maximum before OOMKill (50% headroom) ... # Prometheus alert for high memory usage (warning before OOMKill) - alert: HighMemoryUsage expr: | (container_memory_working_set_bytes / container_spec_memory_limit_bytes) > 0.9 for: 10m annotations: summary: "Pod {{ $labels.pod }} using {{ $value | humanizePercentage }} of memory limit"
🌐
Red Hat
access.redhat.com › solutions › 5296001
The prometheus-k8s pods in CrashLoopBackOff with OOMKilled Error. - Red Hat Customer Portal
June 14, 2024 - The prometheus container in the prometheus-k8s pod is having multiple restarts. The prometheus-k8s pod is in CrashLoopBackOff with following error: $ oc describe pod prometheus-k8s-0 ... State: Waiting Reason: CrashLoopBackOff Last State: Terminated ...