<p>We can scale the nodes in a Kubernetes cluster based on CPU or Memory, can we autoscale the nodes based on the pod pressure (number of pods per node)?
In many of my cases, the CPU and Memory is not the most demanded resources, but number of pods per node is usually under pressure.</p>

xsqian
<p>In Kubernetes there is no option to offer an auto scaling mechanism based on the number of pods per node. Instead you can use <a href="https://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler" rel="nofollow noreferrer">Cluster Autoscaler</a>. Cluster Autoscaler doesn't depend on load metrics. Instead, it's based on scheduling simulation and declared Pod requests.  This can create new nodes when there is a demand for more pods and scale down nodes when there are no more pods to schedule on them, effectively balancing the number of pods per node.  For more information on cluster autoscaling refer to this <a href="https://github.com/kubernetes/autoscaler" rel="nofollow noreferrer">Gitlink</a> and <a href="https://learnk8s.io/kubernetes-autoscaling-strategies" rel="nofollow noreferrer">blog</a> by Daniele Polencic</p>
<p>If in case you are looking for this in GKE then refer to the <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/cluster-autoscaler" rel="nofollow noreferrer">official doc- GKE</a> and <a href="https://cloud.google.com/architecture/best-practices-for-running-cost-effective-kubernetes-applications-on-gke#cluster_autoscaler" rel="nofollow noreferrer">Cluster Autoscaler</a></p>
<p>If you need this feature to implement this in future, you can also raise an issue request <a href="https://cloud.google.com/support/docs/issue-trackers" rel="nofollow noreferrer">here</a>.</p>
<p><strong>EDIT :</strong></p>
<p>@xsqian : Based on your comments, you are using AWS <code>m5.2xlarge</code>  instances. The maximum number of pods per EKS instance are actually listed in this  <a href="https://github.com/awslabs/amazon-eks-ami/blob/master/files/eni-max-pods.txt" rel="nofollow noreferrer">eni-max-pods git link</a></p>
<p>The <a href="https://github.com/awslabs/amazon-eks-ami/blob/master/files/eni-max-pods.txt" rel="nofollow noreferrer">formula</a> for defining the maximum number of pods per instance is as follows:</p>
<blockquote>
<p>N * (M-1) + 2</p>
<p>Where:</p>
<ul>
<li>N is the number of Elastic Network Interfaces (ENI) of the instance type</li>
<li>M is the number of IP addresses of a single ENI</li>
</ul>
<p>Values for <code>N</code> and <code>M</code> for each instance type in this <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html#AvailableIpPerEN" rel="nofollow noreferrer">Elastic network
interface doc</a></p>
</blockquote>
<p>Based on this as you are using <code>m5.2xlarge</code> the pod limit is 58 only and as you are using two nodes then the pod limit is 116 only. This is a soft limit only you can't add anymore pods beyond the 116, if you try to add then this will move into a pending state.</p>
<p>But It is advised that as of August 2021 it's now possible to increase the max pods on a node using the latest AWS CNI plugin as described in this <a href="https://aws.amazon.com/blogs/containers/amazon-vpc-cni-increases-pods-per-node-limits/" rel="nofollow noreferrer">amazon-vpc-cni-increases-pods-per-node-limits</a> and refer to this <a href="https://docs.aws.amazon.com/eks/latest/userguide/cni-increase-ip-addresses.html" rel="nofollow noreferrer">EKS user guide</a>.</p>
