<h2>Specs</h2>
<p>I have a Kubernetes cluster with following configuration (giving only relevant info)</p>
<ul>
<li><p>I have two worker nodes with c5.xlarge configuration (c5.xlarge 4vCPU 8GiB Memory). To clarify these are two EC2 VMs on Amazon AWS.</p>
</li>
<li><p>I am running a backend application on both the nodes</p>
</li>
</ul>
<h2>Requirement</h2>
<ol>
<li><p>When the memory utilization of any node (VM) reaches 80%, i want the node to stop spawning any more pods</p>
</li>
<li><p>Naturally, I would want a new node (VM) to spawn up automatically if both of my existing VM's are at 80% memory threshold.</p>
</li>
</ol>
<h2>Already gone through</h2>
<p><a href="https://stackoverflow.com/questions/60378117/limit-the-number-of-pods-per-node">question</a> It gives a way to achieve but there is no memory parameter involved.</p>

codeaprendiz
<p>You need to scale in 2 levels.</p>

<ol>
<li><p>Pod level autoscaling. This can be achieved by using the HPA (<a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/" rel="nofollow noreferrer">Horizontal Pod Autoscaler</a>). You can set a scaling policy based on CPU and/or Memory metric.</p></li>
<li><p>You have to set node level autoscaling. Ref: <a href="https://docs.aws.amazon.com/eks/latest/userguide/cluster-autoscaler.html" rel="nofollow noreferrer">Cluster Autoscaler</a></p></li>
</ol>

<blockquote>
  <p>The Kubernetes Cluster Autoscaler automatically adjusts the number of nodes in your cluster when pods fail to launch due to lack of resources or when nodes in the cluster are underutilized and their pods can be rescheduled onto other nodes in the cluster.</p>
</blockquote>

<p>Also, note that the cluster autoscaler decide when to scale out and scale in based on the resource availability (Memory or CPU). I don't think you can set a 80% memory threshold as a scaling policy here.</p>

<p>AWS EKS Documentation for scaling <a href="https://docs.aws.amazon.com/eks/latest/userguide/autoscaling.html" rel="nofollow noreferrer">AWS EKS Autoscaling</a></p>
