Skip to content

Node Scaling ​

There are two ways to scale your Kubernetes cluster, either you scale it manually setting the Replicas on the Machine Deployment, or you configure the Cluster-Autoscaler application and just set the min and max replicas.

Manually setting the Node replicas ​

You can edit the machine deployment and set the Replicas field to the desired value.

KS Edit a Machine Deployment

After saving the changes, the nodes will be added or removed automatically until the desired number is reached.

Configure Cluster-Autoscaler ​

The Cluster-Autoscaler is an application that needs to be installed on each cluster. If you checked the Enable Cluster-Autoscaler application during cluster creation it is already installed, otherwise you will have to add it manually.

Add Cluster-Autoscaler to an existing cluster ​

To check if the Cluster-Autoscaler application is installed, go to the cluster detail view, and at the bottom of the page open the "Applications" tab.

KS List applications

You will need to check the toggle Show System Application to see the Cluster-Autoscaler.

If the Cluster-Autoscaler is not installed you can install it using the Add Application button.

KS Add applications

In the pop-up you will see a list of Applications that are available, one of which is the Cluster-Autoscaler.

KS Add Autoscaler

After choosing the Cluster-Autoscaler, you will be asked twice for more configurations, which do not need to be changed.

You can verify that the Cluster-Autoscaler is running, by listing the deployments in kube-system namespace of your user cluster.

bash
kubectl get deployments --kubeconfig=./kubeconfig --namespace kube-system

Configure autoscaling limits for a Machine Deployment ​

If the Cluster-Autoscaler is installed, you can configure the Min Replicas and Max Replicas on each Machine Deployment, to make it scale automatically.

You can edit the machine deployment and under Cluster Autoscaling you can configure the min and max values for the autoscaler.

KS Edit a Machine Deployment

⚠️ Important

You must configure both values for the Autoscaler to work.

Further configuration ​

Beyond the basic min/max replica settings, a user can customize the Cluster-Autoscaler behavior by modifying its application values. This is done by adding the extraArgs property to the autoscaler deployment via the Helm chart values.

Configuring via KKP Dashboard ​

  1. Navigate to the cluster detail view
  2. Open the Applications tab and enable Show System Applications
  3. Find the Cluster-Autoscaler application and click the Edit (pen) icon
  4. In the editor, modify the values field to include the desired extraArgs

Configuring via kubectl ​

It is also possible to edit the ApplicationInstallation custom resource directly:

bash
kubectl edit applicationinstallation cluster-autoscaler -n kube-system

In the spec.valuesBlock section provide a custom configuration as a YAML string. The autoscaler values follow the cluster-autoscaler Helm chart structure.

Example: Custom extraArgs ​

The following example shows how to configure additional autoscaler parameters via the application values. The three default extraArgs (logtostderr, stderrthreshold, v) should always be included.

yaml
extraArgs:
  logtostderr: true
  stderrthreshold: info
  v: 4
  scale-down-delay-after-add: 20m
  scale-down-unneeded-time: 15m
  scale-down-utilization-threshold: 0.3
  max-drain-parallelism: 5
  parallel-scale-up: true

Common extraArgs explained ​

ParameterDescriptionDefault
logtostderrLog to standard error outputtrue
stderrthresholdSeverity level threshold for stderr logginginfo
vLog verbosity level4
scale-down-delay-after-addHow long after a scale-up the autoscaler waits before considering scale-down10m
scale-down-unneeded-timeHow long a node must be unneeded before it is eligible for scale-down10m
scale-down-utilization-thresholdNode utilization level below which a node can be considered for scale-down (0.0 - 1.0)0.5
max-drain-parallelismMaximum number of nodes that can be drained in parallel during scale-down1
parallel-scale-upWhether to allow scaling up multiple node groups simultaneouslyfalse

Hint

A comprehensive list of all available extraArgs parameters is documented in the upstream Cluster Autoscaler FAQ and the Helm chart documentation on Artifact Hub.

Scale from/to Zero ​

If you have workloads that do not run continuously, you can configure the Cluster-Autoscaler to scale a MachineDeployment down to zero nodes when there is no demand, and back up when pods are pending. This is useful for cost optimization, as nodes are only provisioned when actually needed.

Prerequisites ​

  • The Cluster-Autoscaler must be installed on the cluster.
  • The MachineDeployment must be configured with a taint, so that only workloads with a matching toleration trigger a scale-up.
  • The MachineDeployment must have annotations that inform the Cluster-Autoscaler about the node capacity, since no running node is available to inspect when scaled to zero.

Configuring the MachineDeployment ​

1. Add a taint to the MachineDeployment ​

When creating or editing the MachineDeployment, configure a taint to prevent general workloads from being scheduled on these nodes. For example:

dedicated=scale-to-zero:NoSchedule

Only workloads that tolerate this taint will trigger the Cluster-Autoscaler to scale up nodes from this MachineDeployment.

2. Add capacity annotations ​

The Cluster-Autoscaler needs to know the resource capacity of the nodes in a MachineDeployment that is scaled to zero. Add the following annotations to the MachineDeployment:

  • capacity.cluster-autoscaler.kubernetes.io/taints: <TAINT> — informs the autoscaler about the configured taint. Using the example above: capacity.cluster-autoscaler.kubernetes.io/taints: dedicated=scale-to-zero:NoSchedule
  • capacity.cluster-autoscaler.kubernetes.io/cpu: <CPU_COUNT> — the number of allocatable CPUs (e.g. 8)
  • capacity.cluster-autoscaler.kubernetes.io/memory: <MEMORY> — the amount of allocatable memory (e.g. 32Gi)

💡 Tip

The CPU and Memory values are mandatory and must match the values you configured for the MachineDeployment.

⚠️ Enabling scale-to-zero

Currently the Web-UI does not allow setting 0 as the minimum size for the Cluster-Autoscaler. You need to patch the MachineDeployment directly in your user cluster:

bash
kubectl -n kube-system patch md <MD_NAME> --type=json --patch='[{"op": "replace", "path": "/metadata/annotations/cluster.k8s.io~1cluster-api-autoscaler-node-group-min-size", "value": "0"}]'

Configuring your workloads ​

Add a toleration to your Pod spec that matches the taint on the MachineDeployment:

yaml
apiVersion: v1
kind: Pod
metadata:
  name: example-workload
spec:
  tolerations:
  - key: "dedicated"
    operator: "Equal"
    value: "scale-to-zero"
    effect: "NoSchedule"
  containers:
  - name: app
    image: my-app:latest
    resources:
      requests:
        cpu: "500m"
        memory: "512Mi"

When this pod is created and no node with matching capacity and toleration is available, the Cluster-Autoscaler will scale up the MachineDeployment to provision a new node.