Image needs significantly more memory in Kubernetes than just using Docker

277 views
Skip to first unread message

bg

unread,
Mar 28, 2017, 12:39:27 PM3/28/17
to Kubernetes user discussion and Q&A
I have an image that is basic Java application. I'm trying to minimize the amount of memory I submit the Job with in Kubernetes.

Using Java's -Xmx flag I limit the program to using 25MB of memory (-Xmx25m) and using docker I run the container with 30M of memory: docker run -m 30m <image_id>

That works fine so I go and deploy my image (including the -Xmx25m flag) to Kubernetes as a Job with resource request of 30MB of memory and the pods keep terminating with Reason: OOMKilled and Exit Code: 137.

So I start doubling the amount of memory requested: 64M, 128, 256, 512 until finally the pods are successful at 512MB of memory!

So my question is why would a program that can run in docker with 30MB of memory require 512MB of memory when submitted to a kubernetes cluster?


Tim Hockin

unread,
Mar 28, 2017, 12:56:41 PM3/28/17
to kubernet...@googlegroups.com
Wild guess - something is looking at underlying OS or hardware info (e.g. number of processors) and scalng memory or threads based on that.

--
You received this message because you are subscribed to the Google Groups "Kubernetes user discussion and Q&A" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-users+unsubscribe@googlegroups.com.
To post to this group, send email to kubernetes-users@googlegroups.com.
Visit this group at https://groups.google.com/group/kubernetes-users.
For more options, visit https://groups.google.com/d/optout.

EJ Campbell

unread,
Mar 28, 2017, 1:02:49 PM3/28/17
to kubernet...@googlegroups.com
You could also have something in your program that allocates memory off java's heap. Here is a simplified program you can use to test: https://github.com/areese/JavaOOM/blob/master/README.md 

And slightly off topic, newer Jaca's have suppprt for recognizing the memory limits of the container it is running in:
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-use...@googlegroups.com.
To post to this group, send email to kubernet...@googlegroups.com.

David Oppenheimer

unread,
Mar 28, 2017, 4:29:11 PM3/28/17
to Kubernetes user discussion and Q&A
If you specify a memory limit but no request, Kubernetes automatically sets memory request as the same value.
If you specify a memory request but no limit, Kubernetes does not set any memory limit, so your container should never be killed due to exceeding its memory limit.
You said you are setting request of 30MB but didn't say anything about limit -- are you setting a limit?

BTW we really should rename "OOMKilled" to something like "MemoryLimitExceeded" to distinguish it from when a container is killed due to the system actually running out of memory (killed due to system OOM or userspace out-of-resource handler).


--
You received this message because you are subscribed to the Google Groups "Kubernetes user discussion and Q&A" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-users+unsubscribe@googlegroups.com.
To post to this group, send email to kubernetes-users@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages