This container runs fine on Docker on my laptop, but crashes with java.lang.OutOfMemoryError: Java heap space when run in Kubernetes. Why?
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: mem-eater
spec:
template:
metadata:
labels:
# Refer to this name when defining a service.
app: mem-eater
spec:
containers:
# This is the docker image on your docker registry. This one is on
# the official Docker registry.
- image: neilhwatson/memory-eater:prod
name: mem-eater
It tried setting resource limits and requests, and JVM Xmx limits, but in all cases the crash is exactly the same.
Other info:
Have you tried the -XX:+UseCGroupMemoryLimitForHeap
option? It tells the JVM to use the cgroup-provided limits for determining heap sizes (and other resource limits) rather than the system-wide limits.
Christine Flood wrote a great article on some flags that are immensely useful when using Java on containers: https://developers.redhat.com/blog/2017/04/04/openjdk-and-containers/
I have the exact opposite situation, crashing with
docker run -it neilhwatson/memory-eater:prod
while in Kubernetes runs fine, no restarts (but after 511 iterations stops logging).
(sorry for not commenting, I don't have enough rep).