<p>In my 1 node AKS, I deploy multiple job resources (kind:jobs) that are terminated after the task is completed. I have enabled Cluster Autoscaler to add a second node when too many jobs are consuming the first node memory, however it scales out after a job/pod is unable to be created due to lack of memory.</p>
<p>In my job yaml I also defined the resource memory limit and request.</p>
<p>Is there a possibility to configure the Cluster Autoscaler to scale out proactively when it reaches a certain memory threshold (e.g., 70% of the node memory) not just when it cannot deploy a job/pod?</p>

Mike Me
<p>In Kubernetes you can find 3 Autoscaling Mechanisms: <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/" rel="noreferrer">Horizontal Pod Autoscaler</a>, <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/verticalpodautoscaler" rel="noreferrer">Vertical Pod Autoscaler</a> which both can be controlled by metrics usage and <a href="https://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler" rel="noreferrer">Cluster Autoscaler</a>.</p>
<p>As per <a href="https://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler" rel="noreferrer">Cluster Autoscaler Documentation</a>:</p>
<blockquote>
<p>Cluster Autoscaler is a tool that automatically adjusts the size of the Kubernetes cluster when one of the following conditions is true:</p>
<ul>
<li>there are pods that failed to run in the cluster due to insufficient resources.</li>
<li>there are nodes in the cluster that have been underutilized for an extended period of time and their pods can be placed on other existing nodes.</li>
</ul>
</blockquote>
<p>In <a href="https://learn.microsoft.com/en-us/azure/aks/cluster-autoscaler" rel="noreferrer">AKS Cluster Autoscaler Documentation</a> you can find note that <code>CA</code> is Kubernetes Component, not something AKS specific:</p>
<blockquote>
<p>The cluster autoscaler is a Kubernetes component. Although the AKS cluster uses a virtual machine scale set for the nodes, don't manually enable or edit settings for scale set autoscale in the Azure portal or using the Azure CLI. Let the Kubernetes cluster autoscaler manage the required scale settings.</p>
</blockquote>
<p>In <a href="https://learn.microsoft.com/en-us/azure/aks/cluster-autoscaler#about-the-cluster-autoscaler" rel="noreferrer">Azure Documentation - About the cluster autoscaler</a> you have information that AKS clusters can scale in one of two ways:</p>
<blockquote>
<p>The <code>cluster autoscaler</code> watches for pods that can't be scheduled on nodes because of resource constraints. The cluster then automatically increases the number of nodes.</p>
<p>The <code>horizontal pod autoscaler</code> uses the Metrics Server in a Kubernetes cluster to monitor the resource demand of pods. If an application needs more resources, the number of pods is automatically increased to meet the demand.</p>
</blockquote>
<p>On <code>AKS</code> you can adjust a bit your <code>Autoscaler Profile</code> to change some default values. More detail can be found in <a href="https://learn.microsoft.com/en-us/azure/aks/cluster-autoscaler#using-the-autoscaler-profile" rel="noreferrer">Using the autoscaler profile</a></p>
<p>I would suggest you to read the <a href="https://medium.com/kubecost/understanding-kubernetes-cluster-autoscaling-675099a1db92" rel="noreferrer">Understanding Kubernetes Cluster Autoscaling</a> article which explains how <code>CA</code> works. Under <code>Limitations</code> part you have information:</p>
<blockquote>
<p>The cluster autoscaler <strong>doesn’t take into account actual CPU/GPU/Memory usage</strong>, just resource requests and limits. Most teams overprovision at the pod level, so in practice we see aggressive upscaling and conservative downscaling.</p>
</blockquote>
<h2>Conclusion</h2>
<p><code>Cluster Autoscaler</code> doesn't consider actual resources usage. <code>CA</code> downscale or upscale might take a few minutes depending on cloud provider.</p>
