<p>A node on my 5-node cluster had memory usage peak at ~90% last night. Looking around with <code>kubectl</code>, a single pod (in a 1-replica deployment) was the culprit of the high memory usage and was evicted.</p>
<p>However, logs show that the pod was evicted about 10 times (AGE corresponds to around the time when memory usage peaked, all evictions on the same node)</p>
<pre><code>NAMESPACE           NAME                                  READY   STATUS                   RESTARTS   AGE
example-namespace   example-deployment-84f8d7b6d9-2qtwr   0/1     Evicted                  0          14h
example-namespace   example-deployment-84f8d7b6d9-6k2pn   0/1     Evicted                  0          14h
example-namespace   example-deployment-84f8d7b6d9-7sbw5   0/1     Evicted                  0          14h
example-namespace   example-deployment-84f8d7b6d9-8kcbg   0/1     Evicted                  0          14h
example-namespace   example-deployment-84f8d7b6d9-9fw2f   0/1     Evicted                  0          14h
example-namespace   example-deployment-84f8d7b6d9-bgrvv   0/1     Evicted                  0          14h
...
</code></pre>
<p>node memory usage graph:
<a href="https://i.stack.imgur.com/EEUNi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EEUNi.png" alt="mem_usg_graph" /></a></p>
<pre><code>Status:         Failed
Reason:         Evicted
Message:        Pod The node had condition: [MemoryPressure].
</code></pre>
<p>My question is to do with how or why this situation would happen, and/or what steps can I take to debug and figure out why the pod was repeatedly evicted? The pod uses an in-memory database so it makes sense that after some time it eats up a lot of memory, but it's memory usage on boot shouldn't be abnormal at all.</p>
<p>My intuition would have been that the high memory usage pod gets evicted, deployment replaces the pod, new pod isn't using that much memory, all is fine. But the eviction happened many times, which doesn't make sense to me.</p>

<p>The simplest steps are to run the following commands to debug and read the logs from the specific Pod.</p>
<p>Look at the <a href="https://kubernetes.io/docs/tasks/debug-application-cluster/debug-pod-replication-controller/#debugging-pods" rel="nofollow noreferrer">Pod's states and last restarts</a>:</p>
<pre><code>kubectl describe pods ${POD_NAME}
</code></pre>
<p>Look for it's node name and run the same for the node:</p>
<pre><code>kubectl describe node ${NODE_NAME}
</code></pre>
<p>And you will see some information in <code>Conditions</code> section.</p>
<p><a href="https://kubernetes.io/docs/tasks/debug-application-cluster/debug-running-pod/#examine-pod-logs" rel="nofollow noreferrer">Examine pod logs</a>:</p>
<pre><code>kubectl logs --previous ${POD_NAME} ${CONTAINER_NAME}
</code></pre>
<p>If you want to rerun your pod and watch the logs directly, rerun your pod and do the command:</p>
<pre><code>kubectl logs ${POD_NAME} -f
</code></pre>
<p>More info with <code>kubectl logs</code> command and its flags <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#logs" rel="nofollow noreferrer">here</a></p>
