<p>I've configured a CronJob with a YAML file (apiVersion: batch/v1beta1) with resource requests and limits, the pod is successfully instantiated and works till its natural end, but when terminates I saw it marked as OOMKilled.</p>

<p>My pod is working with a Docker container, which is started with a bash script that invokes some Java tools (like maven). I tried to setup a MAVEN_OPTS and JAVAOPTS like this:</p>

<pre><code>        env:
          - name: JAVA_OPTS
            value: "-Xms256M -Xmx1280M"
          - name: MAVEN_OPTS
            value: "-Xms256M -Xmx1280M"
</code></pre>

<p>That are values lower than the ones of the configured limit in the YAML.</p>

<p>I'd expected that the pod stops in complete status as the last echo of my ENTRY_POINT bash script is shown in the log of the pod but I get the OOMKilled.</p>

tassadar
<p>When Containers have resource requests specified, the scheduler can make better decisions about which nodes to place Pods on. But keep in mind: Compute Resources (CPU/Memory) are configured for Containers, not for Pods.</p>

<p>If a Pod container is OOM killed, <a href="https://kubernetes.io/docs/tasks/administer-cluster/out-of-resource/#node-oom-behavior" rel="nofollow noreferrer">the Pod is not evicted</a>. The underlying container is restarted by the <code>kubelet</code> based on its <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy" rel="nofollow noreferrer"><code>RestartPolicy</code></a>.</p>

<p>Your container <a href="https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#my-container-is-terminated" rel="nofollow noreferrer">being terminated</a> by OOMKill does not imply the pod to become in a <code>Completed/Error</code> status (unless you're using the <code>RestartPolicy: Never</code>).</p>

<p>If you do a <code>kubectl describe</code> on your pod, the container will be in <code>Running</code> state, but you can find the last restart cause in <code>Last State</code>. Also, you can check how many times it was restarted:</p>

<pre><code>State:          Running
  Started:      Wed, 27 Feb 2019 10:29:09 +0000
Last State:     Terminated
  Reason:       OOMKilled
  Exit Code:    137
  Started:      Wed, 27 Feb 2019 06:27:39 +0000
  Finished:     Wed, 27 Feb 2019 10:29:08 +0000
Restart Count:  5
</code></pre>
