<p>If I understand correctly the conditions for Kubernetes to OOM kill a pod or container (<a href="https://komodor.com/learn/how-to-fix-oomkilled-exit-code-137/" rel="nofollow noreferrer">from komodor.com</a>):</p>
<blockquote>
<p>If a container uses more memory than its memory limit, it is terminated with an OOMKilled status. Similarly, if overall memory usage on all containers, or all pods on the node, exceeds the defined limit, one or more pods may be terminated.</p>
</blockquote>
<p>This means that if a container in the pod exceeds the total memory it will be killed (the container) but not the pod itself. Similarly, if there are multiple containers in a pod and the pod itself exceeds its memory limitation, which is the sum of memory limits of all the containers in that pod - the pod will be OOM killed. However, the latter only seems possibly if one of the containers exceeds its memory allowance. In this case - wouldn't the container be killed first?</p>
<p>I'm trying to understand the actual conditions in which a pod is OOM killed instead of a container.</p>
<p>I've also noticed that when there is one container in the pod and that container is exceeding its memory allowance repeatedly - the pod and container are killed <strong>intermittently</strong>. I observed this - <em>the container</em> would restart, which would be observable by watching the logs from the pod, and every second time - <em>the pod</em> is killed and restarted, incrementing its restart count.</p>
<p>If it helps to understand the behavior - the QOS class of the pod is <code>Burstable</code>.</p>

<p>Pods aren't OOM killed at all. OOMKilled is a status ultimately caused by a kernel process (OOM Killer) that kills processes (containers are processes), which is then recognised by the kubelet which sets the status on the container. If the main container in a pod is killed then by default the pod will be restarted by the kubelet. A pod cannot be terminated, because a pod is a data structure rather than a process. Similarly, it cannot have a memory (or CPU) limit itself, rather it is limited by the sum of its component parts.</p>
<p>The article you reference uses imprecise language and I think this is causing some confusion. There is a <a href="https://medium.com/tailwinds-navigator/kubernetes-tip-how-does-oomkilled-work-ba71b135993b" rel="nofollow noreferrer">better, shorter, article on medium</a> that covers this more accurately, and <a href="https://mihai-albert.com/2022/02/13/out-of-memory-oom-in-kubernetes-part-4-pod-evictions-oom-scenarios-and-flows-leading-to-them/#oom-scenario-3-node-available-memory-drops-below-the-eviction-hard-flag-value" rel="nofollow noreferrer">a longer and much more in depth article here</a>.</p>
