# How to avoid pod use all memory limits

**URL:** <https://discuss.elastic.co/t/how-to-avoid-pod-use-all-memory-limits/230642>\
**Category:** Elastic Cloud on Kubernetes (ECK)\
**Created:** [April 30, 2020, 9:47pm UTC](https://discuss.elastic.co/t/how-to-avoid-pod-use-all-memory-limits/230642 "2020-04-30T21:47:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![levitative](https://avatars.discourse-cdn.com/v4/letter/l/f9ae1b/32.png) [@levitative](https://discuss.elastic.co/u/levitative)\
**Post date:** [April 30, 2020, 9:47pm UTC](https://discuss.elastic.co/t/how-to-avoid-pod-use-all-memory-limits/230642/1 "2020-04-30T21:47:58Z")

</div>

Elastic search always use all memory that I specify as limit to it, no mater how much I increase the limit and downgrade the mix/max heap size. The actual heap is using less than half of the max heap (2GB). The pod keep firing alarm that the memory is closed to the limit. It´s seems that this is by designed. How do configure Elasticsearch to no consume all available pod memory (requested) but no the limit.

```auto
        spec:
          containers:
            - name: elasticsearch
              env:
                - name: ES_JAVA_OPTS
                  value: -Xms2g -Xmx2g
              resources:
                requests:
                  memory: 2Gi
                  cpu: 0.5
                limits:
                  memory: 6Gi
                  cpu: 2

```

---

<div class="post-metadata">

**Author:** ![dkow](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dkow/32/47340_2.png) [@dkow](https://discuss.elastic.co/u/dkow)\
**Post date:** [May 4, 2020, 5:28am UTC](https://discuss.elastic.co/t/how-to-avoid-pod-use-all-memory-limits/230642/2 "2020-05-04T05:28:22Z")

</div>

Hi @levitative, thanks for your question.

Elasticsearch process should not consume more memory than indicated by max heap size. How are you checking the memory usage?  
Also, note that it's recommended to set your requests equal to your limits (for QoS "Guaranteed") and both min/max heap to half of available memory. You can see the [docs](https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-managing-compute-resources.html#k8s-compute-resources-elasticsearch) for more details.

---

<div class="post-metadata">

**Author:** ![levitative](https://avatars.discourse-cdn.com/v4/letter/l/f9ae1b/32.png) [@levitative](https://discuss.elastic.co/u/levitative)\
**Post date:** [May 7, 2020, 5:19pm UTC](https://discuss.elastic.co/t/how-to-avoid-pod-use-all-memory-limits/230642/3 "2020-05-07T17:19:44Z")

</div>

Hello dkow, thanks for the response.

I changed the request memory to 5GB, but did not worked. I'm using Prometheus container\_memory\_usage\_bytes.

---

<div class="post-metadata">

**Author:** ![Anya\_Sabo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anya_sabo/32/49903_2.png) [@Anya\_Sabo](https://discuss.elastic.co/u/Anya_Sabo)\
**Post date:** [May 7, 2020, 8:35pm UTC](https://discuss.elastic.co/t/how-to-avoid-pod-use-all-memory-limits/230642/4 "2020-05-07T20:35:18Z")

</div>

> How do configure Elasticsearch to no consume all available pod memory (requested) but no the limit.

To do that you would want to lower the limit. The OS will use the memory you allow it to cache data. For monitoring Elasticsearch it is more useful to look at the JVM heap usage rather than the pod memory used. The ES docs have additional info on memory usage: [Heap size settings | Elasticsearch Guide [8.11] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 4, 2022, 7:56am UTC](https://discuss.elastic.co/t/how-to-avoid-pod-use-all-memory-limits/230642/5 "2022-11-04T07:56:21Z")

</div>


