This topic describes how to configure auto scaling for a registered cluster.
Prerequisites
When you configure auto scaling, the cluster-autoscaler component is automatically deployed as a Deployment in the registered cluster. Cloud computing nodes that are added to a cluster during a scale-out event may later be removed in a scale-in event. If you install system components that run as Deployments on these nodes, the system components may not be able to provide stable services. Therefore, you must make sure that these components are not scheduled to automatically added cloud computing nodes or on-premises nodes. The following requirements must be met:
A regular node pool is created and scaled out. For more information, see Create and scale out a node pool.
cloud-node-controller is installed. For more information, see Automatic cleanup of NotReady nodes.
The
alibabacloud.com/cloud-worker-nodes=true
label is added to the nodes in the node pool. For more information, see Add a label to multiple nodes at a time.This ensures that the cluster-autoscaler component is automatically scheduled to a node that has the specified label.
A kubectl client is connected to the registered cluster. For more information, see Obtain the kubeconfig file of a cluster and use kubectl to connect to the cluster.
Step 1: Enable auto scaling
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, find the cluster that you want to manage and click its name. In the left-side navigation pane, choose .
On the Node Pools page, click Enable on the right side of Configure Auto Scaling. In the Configure Auto Scaling panel, set the parameters and then click OK.
Configure the cluster-autoscaler component.
After auto scaling is configured, a Deployment is automatically deployed in the cluster.
Run the following command to query a Deployment:
kubectl -n kube-system get deploy |grep cluster-autoscaler
Expected output:
cluster-autoscaler 1/1 1 1 5s
Configure the RAM policy that enables the cluster-autoscaler component to access other resource. The sample code is as follows:
{ "Version": "1", "Statement": [ { "Action": [ "ess:DescribeScalingGroups", "ess:DescribeScalingInstances", "ess:DescribeScalingActivities", "ess:DescribeScalingConfigurations", "ess:DescribeScalingRules", "ess:DescribeScheduledTasks", "ess:DescribeLifecycleHooks", "ess:DescribeNotificationConfigurations", "ess:DescribeNotificationTypes", "ess:DescribeRegions", "ess:CreateScalingRule", "ess:ModifyScalingGroup", "ess:RemoveInstances", "ess:ExecuteScalingRule", "ess:ModifyScalingRule", "ess:DeleteScalingRule", "ecs:DescribeInstanceTypes", "ess:DetachInstances", "ess:ScaleWithAdjustment", "vpc:DescribeVSwitches" ], "Resource": [ "*" ], "Effect": "Allow" } ] }
Run the following commands to specify the AccessKey pair that is used to grant the RAM policy:
export ACCESS_KEY_ID=<ACCESS KEY ID> export ACCESS_KEY_SECRET=<ACCESS KEY SECRET>
Run the following command to create a Secret named alibaba-addon-secret.
kubectl -n kube-system create secret generic alibaba-addon-secret --from-literal='access-key-id=${ACCESS_KEY_ID}' --from-literal='access-key-secret=${ACCESS_KEY_SECRET}'
Step 2: Create a node pool for auto scaling
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, find the cluster that you want to manage and click its name. In the left-side navigation pane, choose .
In the upper-right corner of the Node Pools page, click Create Node Pool.
In the Create Node Pool dialog box, set the node pool parameters. Then, click Confirm Order.
The following table describes some of the parameters. For more information about the parameters, see Create a node pool.
Parameter
Description
Expected Nodes
The number of nodes that you want the node pool to maintain. You can modify this parameter to adjust the number of nodes in the node pool. If you do not want to create nodes in the node pool, set this parameter to 0. For more information, see Scale a node pool.
Operating System
The operating system of the node. The CentOS and Alibaba Cloud Linux operating systems are supported.
ECS Label
Add labels to the ECS instances.
Taints
Add taints to the nodes in the node pool.
Node Label
Add labels to the nodes in the node pool. Example:
workload=auto
.Custom Security Group
Select the security group to which the nodes belong.
Run the following command to check whether the nodes with the node label
workload=auto
can be created in the node pool.kubectl run nginx --image nginx -l workload=auto