Abstract: Container Service currently provides the function of creating node triggers, calling node triggers, and using openAPI to view the requirements for convenient management and automation of the expanded ECS nodes. This article will introduce you to the steps to complete this capability.
Introduction
Alibaba Cloud Container Service has long provided the function of triggering automatic scaling of nodes based on the average CPU/memory usage of the cluster , helping many customers cope with elastic changes in business pressure. The principle is to use Alibaba 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-level users who want to determine whether to expand and shrink according to their own monitoring data and logic, and even expand and shrink nodes at a fixed time. For this scenario, they need to call the expansion or shrinkage. trigger.
Container Service currently provides the function of creating node triggers, calling node triggers, and using openAPI to view the needs of expanded ECS nodes for convenient management and automation. This article will introduce you to the steps to complete this capability.
Create a Node Scaling Triggertrigger_url
- Log in to the Container Service Management Console .
- Click Clusters in the left navigation bar .
-
On the cluster list page, select the cluster to be set up, and click Manage .
-
Click Node Scaling in the left navigation bar , and click Create New Auto Scaling Rule .
-
Go to Configure Node Scaling Rules, check Automatic scaling based on monitoring indicators , and click Next . Please note when configuring constraint rules:
- The optional range of the expansion step is 1 to 5. The current default is 1, and the configuration is not supported.
- Set the minimum number of nodes in the cluster and the maximum number of nodes in the cluster . During scaling, if the number of nodes is less than or equal to the minimum number of nodes in the cluster, the scaling operation will not be performed; during scaling up, if the number of nodes is greater than or equal to the maximum number of nodes in the cluster, the scaling operation will not be performed.
-
Configure the instance specification and click Confirm Configuration .
For information on instance specification configuration, see Creating a Cluster .
Using Node Scaling Triggers
- You can view the trigger URL on the node scaling page
When calling a node scaling trigger, you need to add the following parameters to the trigger URL:
parameter name required semantic optional valuetype | Yes | Telescopic type | Scaling: scale_in Scaling : scale_out |
step | Yes | Scaling configuration | Positive integer, 1-100, only used for expansion |
For example, when the user needs to elastically expand 1 node, the URL of the trigger is
https://cs.console.aliyun.com/hook/trigger?triggerUrl=<triggerUrl>=&secret=<secret>&type=scale_out&step=1
When the user needs to elastically shrink, the trigger's URL is
https://cs.console.aliyun.com/hook/trigger?triggerUrl=<triggerUrl>=&secret=<secret>&type=scale_in
Note: Currently elastic shrink only supports single node shrink
When calling elastic scaling, you can simply use the curl command to trigger
curl "https://cs.console.aliyun.com/hook/trigger?triggerUrl=<triggerUrl>=&secret=<secret>&type=scale_in"
Use OpenAPI to query elastically extended ECS node information
1. First you need to install the core library of the sdk
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 elastically extended 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('<集群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:
Manage access
Your-Access-Key-Id
and _Your-Access-Key-Secret
Region-Id
It is the Id corresponding to the region, such as East China 2cn-shanghai
, which can be queried through the API
集群ID
is the ID of the container cluster, which can be viewed on the cluster management pageYou can query the ECS ID, private IP, and operating system type from the running 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
Summarize
Through the above content, you can learn how to create node scaling triggers, use the node triggers provided by Alibaba Cloud to automatically trigger cluster scaling on time and on demand, and query scaling node information.
Original link: http://click.aliyun.com/m/30449/