Cluster Autoscaler
Cluster Autoscaler provides the ability to automatically scale-up or scale-down the number of worker nodes in a cluster, based on the number of pending pods to be scheduled. Running the Cluster Autoscaler is optional.
Unlike Horizontal-Pod Autoscaler, Cluster Autoscaler does not depend on any Metrics server and does not need Prometheus or any other metrics source.
The Cluster Autoscaler looks at the following annotations on a MachineDeployment to determine its scale-up and scale-down ranges:
cluster.x-k8s.io/cluster-api-autoscaler-node-group-min-size
cluster.x-k8s.io/cluster-api-autoscaler-node-group-max-size
The full list of command line arguments to the Cluster Autoscaler controller is found this topic.
For more information about how Cluster Autoscaler works, see these documents:
- What is Cluster Autoscaler
- How does scale-up work
- How does scale-down work
- CAPI Provider for Cluster Autoscaler
Cluster Autoscaler Prerequisites
Before you begin, you must have:
Run Cluster Autoscaler
The Cluster Autoscaler controller runs on the workload cluster. Upon creation of the workload cluster, this controller does not have all the objects required to function correctly until after a dkp move
is issued from the bootstrap cluster.
Run the following steps to enable Cluster Autoscaler:
-
Ensure the Cluster Autoscaler controller is up and running (no restarts and no errors in the logs)
kubectl --kubeconfig=${CLUSTER_NAME}.conf logs deployments/cluster-autoscaler cluster-autoscaler -n kube-system -f
-
Enable Cluster Autoscaler by setting the min & max ranges
kubectl --kubeconfig=${CLUSTER_NAME}.conf annotate machinedeployment ${NODEPOOL_NAME} cluster.x-k8s.io/cluster-api-autoscaler-node-group-min-size=2 kubectl --kubeconfig=${CLUSTER_NAME}.conf annotate machinedeployment ${NODEPOOL_NAME} cluster.x-k8s.io/cluster-api-autoscaler-node-group-max-size=6
-
The Cluster Autoscaler logs will show that the worker nodes are associated with node-groups and that pending pods are being watched.
-
To demonstrate that it is working properly, create a large deployment which will trigger pending pods.
cat <<EOF | kubectl --kubeconfig=${CLUSTER_NAME}.conf apply -f - apiVersion: apps/v1 kind: Deployment metadata: name: busybox-deployment labels: app: busybox spec: replicas: 600 selector: matchLabels: app: busybox template: metadata: labels: app: busybox spec: containers: - name: busybox image: busybox:latest command: - sleep - "3600" imagePullPolicy: IfNotPresent restartPolicy: Always EOF
Cluster Autoscaler scales up the number of Worker Nodes until there are no pending pods.
-
Scale down the number of replicas for
busybox-deployment
with the command:kubectl --kubeconfig ${CLUSTER_NAME}.conf scale --replicas=30 deployment/busybox-deployment
-
Cluster Autoscaler starts to scale down the number of Worker Nodes after the default timeout of 10 minutes.