title: Java container crashes out of memory in kubernetes
body: <p>This container runs fine on Docker on my laptop, but crashes with java.lang.OutOfMemoryError: Java heap space when run in Kubernetes. Why?</p>
  
  <pre><code>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
  </code></pre>
  
  <p>It tried setting resource limits and requests, and JVM Xmx limits, but in all cases the crash is exactly the same.</p>
  
  <p>Other info:</p>
  
  <ul>
  <li>Using Java 9 64bit </li>
  <li>k8s 1.8.8 installed on AWS using kops.</li>
  <li>Docker CE 17.12</li>
  </ul>