Custom Node Scaling Using Ali Cloud Container Service

Posted by snaack on Mon, 27 May 2019 18:45:41 +0200

brief introduction

Ali Cloud Container Service was available early Cluster-based average CPU/memory usage triggers node autoscaling To help many customers cope with resilient changes in business pressures.The principle is to use Ali Cloud's cloud monitoring capabilities to trigger node scaling when resource usage (cpu and memory) reaches a threshold.

At the same time, there are some enterprise users who want to judge whether to expand and shrink based on their own monitoring data and logic, or even expand and shrink nodes at a fixed time. For this scenario, you need to call the expansion or shrink triggers.

Container services currently provide the ability to create node triggers, call them, and use the openAPI to view the management and automation needs of expanded ECS nodes. This article describes the steps to accomplish this capability.

Create Node Scale Trigger trigger_url

  1. Sign in Container Service Management Console.
  2. Click Clusters in the left navigation bar.
  3. On the Cluster List page, select the cluster you want to set up and click Manage.

  4. Click Node Scaling in the left navigation bar and click New Auto Scaling Rule.

  5. Enter the Configure Node Scaling Rule, check out Auto Scaling Based on Monitoring Indicators, and click Next.

    Configure constraint rules Note:

    • The optional range of expansion step is 1~5, and the default is 1. Configuration is not supported.
    • Set the minimum number of nodes in the cluster and the maximum number of nodes in the cluster.When scaling, if the number of nodes is less than or equal to the minimum number of nodes in the cluster, no scaling operation will be performed; when scaling, if the number of nodes is greater than or equal to the maximum number of nodes in the cluster, no scaling operation will be performed.
  6. Configure the instance specifications and click Confirm Configuration.
    For information on instance specification configuration, see Create Cluster.

Use node scaling triggers

  1. You can view the URL of the trigger on a node-scaled page

When invoking a node scaling trigger, you need to add a parameter to the trigger URL:

Parameter Name Required semantics Optional Value
type yes Scaling Type Compact: scale_in
Expansion: scale_out
step yes Scaling Configuration Positive integer, 1-100, used only for expansion

For example, when the user needs to resiliently extend a node, the URL of the trigger is

https://cs.console.aliyun.com/hook/trigger?triggerUrl=<triggerUrl>=&secret=<secret>&type=scale_out&step=1

The URL of the trigger is

https://cs.console.aliyun.com/hook/trigger?triggerUrl=<triggerUrl>=&secret=<secret>&type=scale_in

Note: Currently elastic contraction only supports single node contraction

When invoking resilient scaling, it is easy to trigger with the curl command

curl "https://cs.console.aliyun.com/hook/trigger?triggerUrl=<triggerUrl>=&secret=<secret>&type=scale_in"

Query Elastically Extended ECS Node Information Using OpenAPI

1. The core library of sdk needs to be installed first

sudo pip install aliyun-python-sdk-core
sudo pip install aliyun-python-sdk-cs==2.2.0

2. Use python code to query and display resilient expanded nodes

The sample code is as follows:

from aliyunsdkcore.client import AcsClient
from aliyunsdkcs.request.v20151215 import DescribeClusterScaledNodeRequest
import json

req = DescribeClusterScaledNodeRequest.DescribeClusterScaledNodeRequest()
client = AcsClient(ak='<Your-Access-Key-Id>', secret='<Your-Access-Key-Secret>', region_id='<Region-Id>')
req.set_ClusterId('<colony ID>')

status, headers, body = client.get_response(req)
if status == 200:
    hosts = json.loads(body)
    for host in hosts:
        print("Scaledout Instance's ECS ID: {}, IP: {}, OSVersion: {} \n".format(host["InstanceId"], host["IP"], host["OperatingSystem"]))


Code description:

adopt Access Key Management Get Your-Access-Key-Id and Your-Access-Key-Secret

Region-Id is the Id corresponding to the region, e.g. East China 2 is cn-shanghai Hai, which can be passed through API Query

The cluster ID is the ID of the container cluster, which can be accessed by Cluster Management Page See

The ECS ID, private IP, and operating system type can be queried from the run results

Sample output:

Scaledout Instance's ECS ID: i-2zec33gu8do3wrlscdi5, IP: 10.136.125.22, OSVersion: Ubuntu 14.04.5 LTS

Scaledout Instance's ECS ID: i-2ze2qqe4tpakz4xidaw2, IP: 10.136.125.25, OSVersion: Ubuntu 14.04.5 LTS

summary

From the above, you can learn how to create a node scaling trigger, use the node triggers provided by Ali Cloud, trigger cluster expansion on time and on demand automatically, and query the expansion node information.

Topics: SDK Python curl sudo