With the Kubernetes Cluster Autoscaler, you can automatically adjust the number of worker nodes in a node pool based on the needs of your workloads. For each node pool, you configure a minimum and maximum number of nodes. The autoscaler adds or removes nodes within these limits. In this guide, we explain how to use the Kubernetes Cluster Autoscaler on a Kubernetes cluster at TransIP.
- The Cluster Autoscaler is available from Kubernetes 1.35 onwards (also see ‘how do I update my Kubernetes version?’). Older Kubernetes versions are not supported.
- The feature is disabled by default and can currently only be configured through the TransIP API. Support in the control panel will be added later.
- The Kubernetes Cluster Autoscaler scales worker nodes, not the number of pods. If you want to automatically adjust the number of pods, you can use the Horizontal Pod Autoscaler (HPA), for example. Both features can be used alongside each other.
- The TransIP API endpoints used are marked as experimental in the documentation and may still change.
- If you have multiple node pools, you configure autoscaling separately for each node pool you want to use it on.
Requirements for the Kubernetes Cluster Autoscaler
To configure autoscaling, you need the following:
- A TransIP Kubernetes cluster running Kubernetes 1.35 or newer.
- A valid token for the TransIP API.
- The name of the Kubernetes cluster: you can find this in the TransIP control panel in your cluster overview. It looks like ‘k818x’, for example.
Using the Kubernetes Cluster Autoscaler
Use an API PUT request to enable the Cluster Autoscaler on a specific node pool and configure a minimum and maximum number of nodes.
- If the maximum number of nodes has been reached, pods that no longer fit in the cluster may remain in the ‘Pending’ status.
- PodDisruptionBudgets, local storage, strict node selectors or affinity rules, and the annotation cluster-autoscaler.kubernetes.io/safe-to-evict: "false" may prevent the Cluster Autoscaler from automatically removing a node.
Step 1 - retrieve the node pool UUIDs
First, retrieve the node pools for the cluster. Replace [token] and [clustername] with your own details:
curl --request GET \
--header "Content-Type: application/json" \
--header "Authorization: Bearer [token]" \
"https://api.transip.nl/v6/kubernetes/clusters/[clustername]/node-pools" In the output, you will find the uuid field for each node pool. You will need this UUID in the next step.
Step 2 - enable autoscaling
Enable autoscaling with a PUT request to the desired node pool. Adjust the following details in the command:
-
"minNodeCount": <x>determines the minimum number of nodes (two in the example below) -
"maxNodeCount": <x>determines the maximum number of nodes to configure (five in the example below) -
[clustername]: replace this with the name of your Kubernetes cluster -
[nodepool-uuid]: replace this with the UUID of the node pool on which the Cluster Autoscaler is enabled; see step 1 in the previous section.
curl --request PUT \
--header "Content-Type: application/json" \
--header "Authorization: Bearer [token]" \
--data '{ "nodePool": { "autoscalingEnabled": true, "minNodeCount": 2, "maxNodeCount": 5 } }' \
"https://api.transip.nl/v6/kubernetes/clusters/[clustername]/node-pools/[nodepool-uuid]"If the change is successful, the API responds with status code 204 No Content.
Step 3 - check your updated node pool
Next, check whether the Cluster Autoscaler has been configured correctly.
curl --request GET \
--header "Content-Type: application/json" \
--header "Authorization: Bearer [token]" \
"https://api.transip.nl/v6/kubernetes/clusters/[clustername]/node-pools/[nodepool-uuid]"The response includes the following fields, among others:
{
"autoscalingEnabled": true,
"minNodeCount": 2,
"maxNodeCount": 5
}
Disabling the Kubernetes Cluster Autoscaler
You can easily disable the Cluster Autoscaler through the TransIP API with a PUT request to the desired node pool. Set the ‘autoscalingEnabled’ option to ‘false’.
Adjust the following details in the command:
-
"minNodeCount": <x>determines the minimum number of nodes (two in the example below) -
"maxNodeCount": <x>determines the maximum number of nodes to configure (five in the example below) -
[clustername]: replace this with the name of your Kubernetes cluster -
[nodepool-uuid]: replace this with the UUID of the node pool on which the Cluster Autoscaler is enabled; see step 1 in the previous section.
The ‘autoscalingEnabled’, ‘minNodeCount’, and ‘maxNodeCount’ options are always required. If any of these fields is missing, the API will reject the change.
curl --request PUT \
--header "Content-Type: application/json" \
--header "Authorization: Bearer [token]" \
--data '{ "nodePool": { "autoscalingEnabled": false, "minNodeCount": 2, "maxNodeCount": 5 } }' \
"https://api.transip.nl/v6/kubernetes/clusters/[clustername]/node-pools/[nodepool-uuid]"If the change is successful, the API responds with status code 204 No Content.
This concludes our guide to using the Cluster Autoscaler in a Kubernetes cluster at TransIP. For more technical information about scaling decisions, see the Kubernetes Cluster Autoscaler FAQ. For more information about the Kubernetes fields and endpoints available through the API, see the TransIP API documentation.