All Products
Search
Document Center

Container Service for Kubernetes:Configure auto scaling

Last Updated:Nov 01, 2023

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:

Step 1: Enable auto scaling

  1. Log on to the ACK console. In the left-side navigation pane, click Clusters.

  2. On the Clusters page, click the name of the cluster that you want to manage and choose Nodes > Node Pools in the left-side navigation pane.

  3. 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.

  4. Configure the cluster-autoscaler component.

    After auto scaling is configured, a Deployment is automatically deployed in the cluster.

    1. 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
    2. 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",
                      "vpc:DescribeVSwitches"
                  ],
                  "Resource": [
                      "*"
                  ],
                  "Effect": "Allow"
              }
          ]
      }
    3. 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>
    4. 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

  1. Log on to the ACK console. In the left-side navigation pane, click Clusters.

  2. On the Clusters page, click the name of the cluster that you want to manage and choose Nodes > Node Pools in the left-side navigation pane.

  3. In the upper-right corner of the Node Pools page, click Create Node Pool.

  4. 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.

  5. 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