Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the role of the AutoScaling life cycle

2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail what the role of the AutoScaling life cycle is, and the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

LifecycleHook introduces LifecycleHook usage scenarios

With LifecycleHook, you can suspend ECS instances that are expanding or are about to be released when a scaling activity occurs in a scaling group, perform user-defined actions, and manage the lifecycle of ECS instances in the scaling group more flexibly. A few simple LifecycleHook application scenarios:

After the ECS instance pops up in the scaling group, it needs to be delayed for a period of time (after the test service is fine) to mount to the SLB, and then provide services to the outside world.

When a scaling group releases an ECS instance, it needs to first remove the instance from the SLB backend service (to prevent receiving new requests), and then stop and release the instance when it is detected that the received request is completed.

Perform data backup when an ECS instance is released by a scaling group

Stretch groups stretch or contract flexibly to perform some user-defined actions

For the second scenario mentioned above, if you can determine the maximum processing time of each request, you can call the API create Lifecycle Hook to create a lifecycle hook, set the parameter value of LifecycleTransition to SCALE_IN, and set HeartbeatTimeout to the maximum processing time of the request. There is no need to set the notification object. When an auto scaling activity occurs, the ECS instance will be suspended for a period of time (HeartbeatTimeout) after it is removed from the SLB, waiting for the request to be processed.

The way LifecycleHook works

When the scaling group creates a LifecycleHook and the scaling activity type (LifecycleTransition) configured by LifecycleHook occurs, then the scaling activity is suspended, and users can perform custom actions during the period when the scaling activity is suspended until the LifecycleHook timeout (HeartbeatTimeout), or terminate the scaling activity in advance by calling the CompleteLifecycleAction API.

For elastic expansion (SCALE_OUT) stretching activities:

The ECS instance first enters the Pending (joining) status. When the instance starts successfully and is added to the RDS whitelist (if RDS is set in the scaling group), LifecycleHook is triggered and the ECS instance enters the Pending:Wait (pending joining) status. If the notification object (MNS) is configured in LifecycleHook, the notification content is sent to MNS. Users can consume messages in MNS topics or queues through the MNS console, or through OpenAPI. For more information, please see ESS event Notification # message receiving section. When users receive MNS messages, they can perform custom actions, such as installing software and deploying services on ECS instances. After performing custom actions, users can end pending scaling activities in advance through the CompleteLifecycleAction API, or they can wait for LifecycleHook to suspend timeout. After the suspension of LifecycleHook, there are two execution directions, CONTINUE or ABANDON. For elastic expansion and scaling activities, the execution direction is explained as follows:

CONTINUE continues, and ECS instances will be put into the scaling group.

ABANDON rejects, scaling activity rolls back, and ECS instance will be released

If multiple LifecycleHook types of elastic expansion are configured in the scaling group, multiple LifecycleHook will be triggered when an elastic expansion activity occurs, and the final execution direction (CONTINUE or ABANDON) of the scaling activity shall be based on the execution direction of the last ending LifecycleHook.

After ending the LifecycleHook suspend state, if the scaling group is configured with load balancer (SLB), after the ECS instance is mounted on the SLB, the instance enters the Inservice (in service) state, and the auto scaling activity ends.

For elastic contraction (SCALE_IN) expansion activities:

The ECS instance first enters the Terminating (moving out) state, and after the instance is removed from the SLB backend server (if the scaling group is configured with load balancer (SLB)), the LifecycleHook is triggered, and the ECS instance goes into the Terminating:Wait (pending during removal) state. If the notification object (MNS) is configured in LifecycleHook, the notification content is sent to MNS. Users can consume messages in MNS topics or queues through the MNS console, or through OpenAPI. For more information, please see ESS event Notification # message receiving section. After receiving the MNS message, the user can perform custom actions, such as checking whether the request received by ECS has been processed, stopping the receiving service, and so on. After performing the custom action, the user can end the pending scaling activity ahead of time through the CompleteLifecycleAction API, or wait for the LifecycleHook to suspend timeout. After the end of LifecycleHook suspension, there are two execution directions, CONTINUE or ABANDON. For elastic scaling activities, the execution direction is explained as follows:

CONTINUE continues and ECS instance will be removed from the scaling group

ABANDON rejected. ECS instance will be removed from the scaling group.

If the scaling group is configured with multiple LifecycleHook of elastic contraction type, multiple LifecycleHook will be triggered when the elastic contraction activity occurs. If a LifecycleHook is suspended and the execution result is ABANDON, the rest of the suspended LifecycleHook will be terminated ahead of time, and the ECS instance will be removed from the scaling group. If the execution result of a LifecycleHook suspension is CONTINUE, the remaining pending LifecycleHook will continue to be suspended until the end of the last LifecycleHook suspension and the scaling activity resumes.

After ending the LifecycleHook pending state, the auto scaling service will first remove the ECS instance from the RDS whitelist (if RDS is configured in the scaling group), then stop the ECS instance (if the ECS instance is popped up by the scaling group and not manually added), release the instance (if the ECS instance is popped up by the scaling group and not manually added), and remove the instance from the scaling group.

LifecycleHook notification mode

If the lifecycle hook is configured with a notification object, when the scaling activity triggers LifecycleHook in the scaling group, the notification object will receive the details of the current scaling activity. If the lifecycle hook is not configured with a notification object, no notification message will be sent when the scaling activity triggers LifecycleHook in the scaling group.

Lifecycle hooks currently support the following two notification methods:

Message Service (MNS) queue (Queue)

Message Service (MNS) topic (Topic)

For an introduction to MNS topics and queues, you can refer to the queue usage help and topic usage help to learn about topics, how queues are created, how messages are received, and how to set subscriptions to topics.

It should be noted that the MNS message service will charge a corresponding fee. For more information, please see Cloud Product pricing # message Service.

LifecycleHook Notification content

When LifecycleHook is triggered by a scaling activity in a scaling group, if the notification object is configured on the lifecycle hook (notification to MNS is only supported), the notification object will receive detailed information about the scaling activity, as shown below:

{"content": {"defaultResult": "CONTINUE", "instanceIds": ["i-xxxxxxxxxx1", "i-xxxxxxxxxx2", "i-xxxxxxxxxx3", "i-xxxxxxxxxx4", "i-xxxxxxxxxx5"], "lifecycleActionToken": "C8BEAE68-CB77-4E60-986D-1E8BBF1A6B99", "lifecycleHookId": "ash-wxxxxxxxxxxx", "lifecycleHookName": "SCALE_IN_TEST" "lifecycleTransition": "SCALE_IN", "notificationMetadata": "Test SCALE_IN HOOK", "requestId": "XXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX", "scalingActivityId": "asa-xxxxxxxxxxxxxxxx", "scalingGroupId": "asg-xxxxxxxxxxxxxxxxx", "scalingGroupName": "test-hook", "scalingRuleId": "asr-xxxxxxxxxxxx", "scheduledTaskId": "xxxxxxxxxxxxxx"}, "product": "ESS" RegionId: "cn-shenzhen", "resourceArn": "acs:ess:cn-shenzhen:111111111111111:scalingGroup/asg-xxxxxxxxxxxxx", "time": "2018-06-21T03:07:57.641Z", "userId": "111111111111111"}

In the above content:

The unique identifier of the resourceArn scaling group, including the Region information to which the scaling group belongs, the user ID information to which the scaling group belongs, and the ID information of the scaling group.

Details of scaling activities triggered by content lifecycle hooks

SCALE_OUT: elastic expansion activity of scaling group

SCALE_IN: elastic contraction activity of scaling group

CONTINUE, continue.

ABANDON refuses

DefaultResult lifecycle hook default enforcement policy

InstanceIds lifecycle hook suspended ECS instance ID

LifecycleActionToken lifecycle hook unique identifier. By getting this parameter and the lifecycleHookId parameter, you can actively end lifecycle activities by calling CompleteLifecycleAction.

LifecycleHookId lifecycle hook ID

LifecycleHookName Lifecycle Hook name

The type of scaling activity applicable to the lifecycleTransition lifecycle hook. Value range:

NotificationMetadata lifecycle hook notification identification

ScalingActivityId scaling activity ID

ScalingGroupId scaling Group ID

ScalingGroupName scaling group name

Name of the scaling rule that scalingRuleId triggers the scaling activity (this parameter is not required)

ScheduledTaskId scheduled task ID (this parameter is available only if the scaling activity is triggered by a scheduled task)

For the consumption of MNS queue or topic content, it is recommended to refer to the long rotation training best practice document officially provided by MNS, and use long polling to consume the message content received by the queue or topic.

Best practices for creating LifecycleHook Notification objects

When creating a LifecycleHook, you can configure the notification object or not. If you need to configure the notification object, you need to create the notification object first, and then create the LifecycleHook. For more information about how to create notification objects (MNS topics, queues), you can refer to the ESS event Notification # create MNS queue section and the ESS event Notification # create MNS topic section.

Create LifecycleHook

The creation of LifecycleHook can be done through the ESS console or by calling the CreateLifecycleHook API. Create a LifecycleHook through the API, which can be implemented based on CreateLifecycleHook documents and refer to the ESS event Notification # creation event Notification (OpenAPI) section. The process of creating a LifecycleHook through the ESS console is as follows:

Log in to the ESS console, go to the lifecycle hook list page, click the create lifecycle hook button, and the pop-up interface is shown below:

Press the prompt name, notification logo, select scaling activity type, execution policy and notification method, and click OK, as shown in the following figure:

In the figure above, two LifecycleHook are created, one LifecycleHook of scaling activity expansion type and one LifecycleHook of scaling activity contraction type.

Trigger LifecycleHook

This chapter takes the triggered elastic contraction activity as an example to show the working process of LifecycleHook. For more information on how to trigger a scaling activity, please see the ESS event Notification # creation event Notification (OpenAPI) section.

First, trigger the scaling activity to reduce one instance, as shown in the following figure:

View the scaling group ECS instance list page, as shown in the following figure:

As you can see from the figure above, an ECS instance is suspended at this time. Since the notification object is set for the elastic contraction type LifecycleHook, you can log in to the MNS console to view the notification result. For more information on how to view the message, please see ESS event Notification # MNS queue message receiving) section.

After receiving the notification sent by LifecycleHook, extract the lifecycleActionToken and lifecycleHookId parameters, and then call the API CompleteLifecycleAction to end the LifecycleHook pending state in advance, as follows:

Public class LifecycleHookTest {public static final String REGION_ID = "cn-hangzhou"; public static final String AK = "xxx"; public static final String AKS = "xxx"; public static void main (String [] args) throws ClientException, Exception {IClientProfile clientProfile = DefaultProfile.getProfile (REGION_ID, AK, AKS); final IAcsClient client = new DefaultAcsClient (clientProfile); completeLifecycleAction (client) } private static String completeLifecycleAction (IAcsClient client) throws ClientException {CompleteLifecycleActionRequest request = new CompleteLifecycleActionRequest (); request.setLifecycleHookId ("ash-xxxxxxxxxxxxx"); request.setLifecycleActionToken ("xxxxxxxxxxxxxxx"); request.setLifecycleActionResult ("CONTINUE"); CompleteLifecycleActionResponse response = client.getAcsResponse (request); return response.getRequestId ();}}

In using the above code, you need to add personal AK information, as well as LifecycleActionToken and LifecycleHookId parameters.

After the LifecycleHook suspend state ends, the ECS instance is stopped (the instance created by the scaling group), then released (the instance created by the scaling group) and moved out of the scaling group.

It is important to note that if the notification object configured by LifecycleHook is deleted, the current LifecycleHook will no longer take effect. If the scaling activity triggers the LifecycleHook to be suspended, and you want to extend the suspension time of the scaling activity, you can extend the suspension time by calling RecordLifecycleActionHeartbeat.

On the role of the AutoScaling life cycle is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report