<p>I am currently seeing a strange issue where I have a Pod that is constantly being <code>Evicted</code> by Kubernetes.</p>
<p><strong>My Cluster / App Information:</strong></p>
<ul>
<li>Node size: <code>7.5GB RAM</code> / <code>2vCPU</code></li>
<li>Application Language: <code>nodejs</code></li>
<li>Use Case: puppeteer website extraction (I have code that loads a website, then extracts an element and repeats this a couple of times per hour)</li>
<li>Running on <code>Azure Kubernetes Service (AKS)</code></li>
</ul>
<p><strong>What I tried:</strong></p>
<ul>
<li><p>Check if Puppeteer is closed correctly and that I am removing any chrome instances. After adding a force killer it seems to be doing this</p>
</li>
<li><p>Checked <code>kubectl get events</code> where it is showing the lines:</p>
</li>
</ul>
<pre class="lang-sh prettyprint-override"><code>8m17s       Normal    NodeHasSufficientMemory   node/node-1              Node node-1 status is now: NodeHasSufficientMemory
2m28s       Warning   EvictionThresholdMet      node/node-1              Attempting to reclaim memory
71m         Warning   FailedScheduling          pod/my-deployment     0/4 nodes are available: 1 node(s) had taint {node.kubernetes.io/memory-pressure: }, that the pod didn't tolerate, 3 node(s) didn't match node selector
</code></pre>
<ul>
<li>Checked <code>kubectl top pods</code> where it shows it was only utilizing ~30% of the node's memory</li>
<li>Added resource limits in my kubernetes <code>.yaml</code>:</li>
</ul>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app-d
spec:
  replicas: 1
  template:
    spec:
      containers:
      - name: main
        image: my-image
        imagePullPolicy: Always
        resources:
          limits: 
            memory: &quot;2Gi&quot;
</code></pre>
<p><strong>Current way of thinking:</strong></p>
<p>A node has X memory total available, however from X memory only Y is actually allocatable due to reserved space. However when running <code>os.totalmem()</code> in <code>node.js</code> I am still able to see that Node is allowed to allocate the X memory.</p>
<p>What I am thinking here is that Node.js is allocating up to X due to its Garbage Collecting which should actually kick in at Y instead of X. However with my limit I actually expected it to see the limit instead of the K8S Node memory limit.</p>
<p><strong>Question</strong></p>
<p>Are there any other things I should try to resolve this? Did anyone have this before?</p>

Xavier Geerinck
<p>You NodeJS app is not aware that it runs in container. It sees only the amount of memory that Linux kernel reports (which always reports the total node memory). You should make your app aware of cgroup limits, see <a href="https://medium.com/the-node-js-collection/node-js-memory-management-in-container-environments-7eb8409a74e8" rel="nofollow noreferrer">https://medium.com/the-node-js-collection/node-js-memory-management-in-container-environments-7eb8409a74e8</a></p>
<p>With regard to Evictions: when you've set memory limits - did that solve your problems with evictions?</p>
<p>And don't trust <code>kubectl top pods</code> too much. It always shows data with some delay.</p>
