Cluster Proportional Autoscaler (CPA) is a controller that automatically scales a specified deployment based on the number of nodes in the cluster. It is especially useful when a service needs to be available on every node or should scale proportionally to the overall cluster resources.
Unlike traditional autoscalers, CPA does not rely on load metrics. Instead, it uses proportional formulas that are manually defined.
CPA supports two modes for calculating the number of replicas:
In linear mode, the number of replicas is calculated using the following formula:
replicas = max(min, min(max, cores / coresPerReplica, nodes / nodesPerReplica))
You can use both parameters (coresPerReplica and nodesPerReplica) or just one. The min and max values set the lower and upper limits for the number of replicas.
Example configuration:
config:
linear:
coresPerReplica: 2
nodesPerReplica: 1
min: 2
max: 20
preventSinglePointFailure: true
includeUnschedulableNodes: true
In this example:
In ladder mode, the number of replicas is explicitly defined using a lookup table. This is useful when you need an exact number of pods for specific cluster sizes.
Example configuration:
config:
ladder:
coresToReplicas:
- [ 1, 1 ]
- [ 64, 3 ]
- [ 512, 5 ]
- [ 1024, 7 ]
- [ 2048, 10 ]
nodesToReplicas:
- [ 1, 1 ]
- [ 2, 2 ]
- [ 5, 3 ]
In this example:
To install Cluster Proportional Autoscaler:
By default, the autoscaler is configured to scale the metrics-server
in the kube-system
namespace using linear mode, creating one pod per node:
config:
linear:
coresPerReplica: 1
nodesPerReplica: 1
min: 1
max: 100
preventSinglePointFailure: true
includeUnschedulableNodes: true
options:
logToStdErr: true
logLevel: 7
namespace: kube-system
target: deployment/metrics-server
If you want to scale a different service—for example, nginx
in the default
namespace—change the target
and namespace
parameters before installing.
To switch scaling modes or parameters, edit the config
section. For instance, you can uncomment the ladder
parameters and use that mode instead of linear
.
When installing via the web UI, only one target resource can be specified using the
target
parameter.
If you want to scale multiple resources—such as both
metrics-server
andcoredns
—you need to use manual installation with multiple autoscaler instances.
If you need more flexibility or want to deploy multiple autoscalers for different services, use Helm for installation.
Step 1: Add the Helm chart repository:
helm repo add cluster-proportional-autoscaler https://kubernetes-sigs.github.io/cluster-proportional-autoscaler
This adds an external source from which the autoscaler can be installed.
Step 2: Update chart list:
helm repo update
Step 3: Create a values.yaml
file with the following content:
config:
linear:
coresPerReplica: 1
nodesPerReplica: 1
min: 1
max: 100
preventSinglePointFailure: true
includeUnschedulableNodes: true
options:
logToStdErr: true
logLevel: 7
namespace: kube-system
target: deployment/metrics-server
serviceAccount:
create: true
This configuration:
nodesPerReplica: 1
)preventSinglePointFailure
(adds an extra pod if only one node exists)Step 4: Install the autoscaler with Helm:
helm upgrade --install metrics-autoscaler cluster-proportional-autoscaler/cluster-proportional-autoscaler --values values.yaml
Step 5: Verify the pod is running:
kubectl get pods -n kube-system
With manual installation, you can run multiple independent autoscaler instances for different services.
To do so:
values-nginx.yaml
filetarget
and namespace
parameters for the deployment (e.g., nginx
in the default
namespace)helm upgrade --install nginx-autoscaler cluster-proportional-autoscaler/cluster-proportional-autoscaler --values values-nginx.yaml
This method allows you to scale any number of services with individual settings.