If I understand correctely -XX:MaxRAMPercentage
sets the maximum java heap size for a JVM.
If I run JVM container in Kubernetes and have -XX:MaxRAMPercentage=60.0
with the following configuration:
resources:
limits:
memory: 1024Mi
requests:
memory: 256Mi
then maximum java heap size = 1024Mi*60% = 614Mi
.
But what will happen if somehow JVM memory will exceed 614Mi? May Kubernetes forces to restart such a container?
This should be the same behavior as directly setting the heap size like -Xmx614M
. If the JVM runs out of Java heap memory, this isn't directly visible to Kubernetes.
The JVM will throw an OutOfMemoryError
, but (since it can't allocate memory or create objects) this is very difficult to recover from. This should cause the JVM itself to exit. But at this point the main process in the container has exited, and this is visible to Kubernetes; the container will get restarted (with the same memory settings) the same way as any other container that exits.