<p>I have a simple Spring Boot application, deployed on k8s (2 pods).
Briefly described this application takes messages from producer and process them to the consumer. Nothing complicated. </p>

<p>UPD: </p>

<ul>
<li>java version: 1.8.172</li>
<li>javaMemoryOpts: -Xmx2048m -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap</li>
</ul>

<p><a href="https://i.stack.imgur.com/tgbcA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tgbcA.png" alt="memory monitoring"></a>
This's a memory consumption for one of 2 podes.</p>

<ul>
<li>blue line - requested memory by k8s</li>
<li>orange line - working set</li>
<li>green line - service usage </li>
<li>yellow line - memory limit by k8s</li>
</ul>

<p>The issue is the high memory usage despite of simplicity of service.
I'd profiled the app, but it seems ok with service: just about 60 threads, no memory leaks and so on. </p>

<p>The used memory never exceed k8s limit even if it's very close to it (no OOM).
Of course, I can add more pods and consumption will become even but I think it's not the right way.</p>

<p>One thing confusing me why used memory always above required even at the start.</p>

<p>Actually, I don't know what's going wrong with it. Does anybody have ideas or maybe know how to reduce app's memory usage?</p>

yevtsy
<p>Generally, Kubernetes represents Requests and limits mechanisms in order to control resources (CPU, Memory). Requests mission aims to provide sufficient amount of resources for the container inside the cluster Pods. Limits guarantee that container will never reach the defined value for a particular resource.Take a tour and visit the following articles:</p>

<ul>
<li><a href="https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/" rel="nofollow noreferrer">Managing Compute Resources for
Containers</a></li>
<li><a href="https://jaxenter.com/manage-container-resource-kubernetes-141977.html" rel="nofollow noreferrer">How to use resource requests and limits in
Kubernetes</a></li>
<li><a href="https://supergiant.io/blog/managing-memory-and-cpu-resources-for-kubernetes-namespaces" rel="nofollow noreferrer">Managing-memory-and-cpu-resources-for-kubernetes-namespaces</a></li>
</ul>

<p>Tuning JVM is quite a complicated process to achieve a good results and sufficient level of computing system utilization. I would recommend to review the next web links about this topic:</p>

<ul>
<li><a href="https://medium.com/@matt_rasband/dockerizing-a-spring-boot-application-6ec9b9b41faf" rel="nofollow noreferrer">Properly limiting the JVM’s memory usage
</a></li>
<li><a href="https://plumbr.io/blog/memory-leaks/why-does-my-java-process-consume-more-memory-than-xmx" rel="nofollow noreferrer">Why does my Java process consume more memory than
Xmx</a></li>
</ul>
