> ## Documentation Index
> Fetch the complete documentation index at: https://inframan.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Autoscaling

> How services add and remove replicas, and how node pools grow and shrink underneath them.

Autoscaling happens at two levels. **Services** add and remove replicas with their load. **Node pools** add and remove nodes so there's room for those replicas, and no more.

## Services

Each web service chooses how it scales with `scaling.type` in [`inframan.yaml`](https://inframan.mintlify.site/deploy/inframan-yaml#scaling):

> [tab] Requests (concurrency)
>
> Scales on concurrent requests per replica. When replicas average more than `target` requests in flight, Knative adds one. Reacts within seconds, and can scale to zero. Needs [Knative](https://inframan.mintlify.site/provision/add-ons/knative.md).
>
> ```yaml inframan.yaml theme={null}
> scaling:
>   type: concurrency
>   min_replicas: 0
>   max_replicas: 10
>   target: 50
> ```
>
> Best for: HTTP services whose cost is in handling requests.

> [tab] CPU and memory (hpa)
>
> A Horizontal Pod Autoscaler adds replicas when average CPU use is above `cpu` percent of the request, or memory above `memory` percent. Keeps at least one replica.
>
> ```yaml inframan.yaml theme={null}
> scaling:
>   type: hpa
>   min_replicas: 2
>   max_replicas: 8
>   cpu: 70
>   memory: 80
> ```
>
> Best for: services whose load shows up as CPU, and any service on an infrastructure without Knative.

> [tab] Fixed (off)
>
> Runs exactly `min_replicas` replicas.
>
> ```yaml inframan.yaml theme={null}
> scaling:
>   type: "off"
>   min_replicas: 2
> ```
>
> Best for: workers, and services that must always run a set number of copies.

Without settings, a service runs between 1 and 5 replicas. `cpu` defaults to 70 and `target` to 100. Workers always run a fixed number of replicas.

> [!TIP]
>
> Autoscaling on CPU percentage is relative to the CPU **request**. Set a realistic `cpu_request` under `resources`, or the autoscaler reacts too early or too late. See [Right-sizing](https://inframan.mintlify.site/optimize/right-sizing.md).

## Nodes

> [tab] Google Cloud
>
> Each node pool autoscales between its **Min nodes** and **Max nodes**. When pods can't be scheduled for lack of room, the pool adds a node. When a node has been underused for a while and its pods fit elsewhere, the pool removes it.
>
> * Application pools default to a minimum of 0, so a pool with nothing on it costs nothing.
> * The system pool runs 1 to 3 nodes on non-production infrastructures.
> * Inframan adds disruption budgets for a few `kube-system` components, so that the autoscaler is allowed to move them and remove nodes.

> [tab] AWS
>
> Karpenter launches nodes for pods waiting to run, choosing an instance from the sizes and families each pool allows, and removes nodes that are empty or underused.
>
> * Each pool is capped by its **vCPU limit**, the total vCPU it may run.
> * On non-production infrastructures, Karpenter consolidates empty and underused nodes after 1 minute.
> * Nodes are replaced after 30 days.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.