0

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:

  • Using Java 9 64bit
  • k8s 1.8.8 installed on AWS using kops.
  • Docker CE 17.12
2
  • Where did you run the Kubernetes? On KGE? Docker by default has no resource limits, Kubernetes sometimes has that in some environments (such as KGE). How did you set mem limits, with namespaces? Commented Feb 20, 2018 at 20:25
  • This blog post explains some stuff: stroebitzer.com/2018/08/02/jvm-k8s.html Commented Oct 8, 2018 at 16:14

2 Answers 2

5

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/

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, I tried the useCGroups setting and MaxRAM, the out of memory crash still happens.
@NeilHWatson were you able to resolve this? I am facing same issue.
2

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).

1 Comment

It's supposed to stop and be idle at 511.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.