# Capi Cluster Auto Scaler Addon

## Introduction

The Platform9 managed Cluster Autoscaler for CAPI clusters ensures the resources of the Kubernetes Cluster Worker Node Groups are never exhausted. More specific information about [Cluster Autoscaler for CAPI ](https://cluster-api.sigs.k8s.io/tasks/automated-machine-management/autoscaling.html)can be found on its specific [GitHub pages](https://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler/cloudprovider/clusterapi).

## Description

The CAPI Cluster Auto-Scaler add-on continually verifies the number of needed pods that are pending allocation for particular Node Groups. If there are pods that are pending for allocation on a particular Node Group nodes, new nodes are then provisioned and added to the node group to accommodate the demand. When demand drops and fewer nodes are needed, the auto-scalar scales down the node groups. After the autoscaler add-on is enabled and the node-groups are annotated for auto-scalar, the behaviour of the auto-scalar is automatic, so users only need to define the number of replicas to be deployed.

## Settings

The CAPI Cluster Auto-Scaler needs to be enabled with cluster creation or post-cluster creation from the add-ons section.

#### Annotating a Node Group for Auto-scalar

Following annotations need to be added to the instance of the node group custom resources.

Example:

{% tabs %}
{% tab title="Bash" %}

```bash
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineDeployment
metadata:
  name: test-md-0
  namespace: default
  annotations:
    cluster.x-k8s.io/cluster-api-autoscaler-node-group-min-size: '3'
    cluster.x-k8s.io/cluster-api-autoscaler-node-group-max-size: '10'
spec:
  ...
```

{% endtab %}
{% endtabs %}

## YAML Specifications

{% tabs %}
{% tab title="YAML" %}

```yaml
apiVersion: sunpike.platform9.com/v1alpha2
kind: ClusterAddon
metadata:
  labels:
    sunpike.pf9.io/cluster: '<clsuuid>'
    type: cluster-auto-scaler-capi
  name: <clsuuid>-cluster-auto-scaler-capi
  namespace: default
spec:
  clusterID: '<clsuuid>'
  override:
    params:
    - name: clusterAutoscalerNamespace
      value: kube-system
    - name: clusterNamespace
      value: test-namespace
    - name: extraArgs
      value: test_key=test_value,test_key2=test_value2
  type: cluster-auto-scaler-capi
  version: 1.21.1
  watch: true
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.platform9.com/managed-kubernetes/5.9/platform9-managed-add-ons-overview/capi-cluster-auto-scaler-addon.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
