The Rolling Update feature of Auto Scaling simplifies the process of updating images and running scripts on Elastic Compute Service (ECS) instances, providing a more efficient approach to managing instances within a scaling group.
Background information
For example, you have a scaling group with the following attributes:
The scaling group is in China (Hangzhou).
The CentOS 6.4 64-bit public image is used in the active scaling configuration of the scaling group.
One hundred ECS instances are created based on the active scaling configuration of the scaling group. All instances are in the In Service state.
No scaling activities are in progress in the scaling group.
Procedure
This topic describes how to update the images of ECS instances in a scaling group to Alibaba Cloud Linux 2 images and how to install Apache on the ECS instances after the images are updated.
Step 1: Create a custom image
Log on to the ECS console.
In the left-side navigation pane, choose .
In the top navigation bar, select the region and resource group to which the resource belongs.
Create an ECS instance.
In the upper-left corner of the Instance page, click Create Instance.
On the Custom Launch tab, select a billing method, region, instance type, and image.
For information about each parameter on the Custom Launch tab, see the Parameters section in this topic.
The following table shows the sample configurations of the instance. Configure other parameters based on your business requirements, and make sure that the configurations are the same as the active scaling configurations in the scaling group.
Parameter
Example
Billing Method
Pay-as-you-go
Region
China (Hangzhou)
Network and Zone
Network: VPC
Zone: Random
Image
Type: Public Image
Version: Alibaba Cloud Linux 2.1903 LTS 64-bit
Before you click Create Order, check the instance configurations in the Configuration Summary section and configure parameters such as Duration on the right side of the page. Make sure that all configurations meet your business requirements.
Read and select service agreements such as the ECS Terms of Service. If you already signed a service agreement, you do not need to re-sign the agreement. Follow the on-screen instructions. Then, click Create Order.
Check the fees of the ECS instance and follow the on-screen instructions to complete the payment.
After the ECS instance is created, go to the Instances page to check the state of the instance. When the ECS instance is in the Running state, the ECS instance is created. Remember to change the name of the ECS instance to
Instance-ForCustomImage
.NoteBefore you create a custom image, you can configure the Instance-ForCustomImage instance. For example, you can deploy applications and copy data. This helps reduce maintenance operations after the image is updated.
Create a custom image from the ECS instance.
Find the Instance-ForCustomImage ECS instance and choose in the Actions column.
Configure parameters to complete image creation.
The following table shows the sample configurations of the image. Configure other parameters based on your business requirements.
Parameter
Example
Name
Image-AliyunLinux
Description
The image that is used to update the images of ECS instances in the scaling group.
Click OK.
Prepare a custom image for rolling purposes.
Find an ECS instance that belongs to the specified scaling group and choose in the Actions column.
Configure parameters to complete image creation.
The following table shows the sample configurations of the image. Configure other parameters based on your business requirements.
Parameter
Example
Name
Image-CentOSBck
Description
The image that is used to roll back the image of the ECS instance when an error occurs in the rolling update task.
Click OK.
In the left-side navigation pane, choose . On the Images page, view the creation progresses of Image-AliyunLinux and Image-CentOSBck.
An image is created when its creation progress reaches 100%.
Step 2: Update an image and execute a script
Log on to the Auto Scaling console.
In the left-side navigation pane, click Scaling Groups.
In the top navigation bar, select the region where Auto Scaling is activated.
Find a scaling group and use one of the following methods to go to the scaling group details page:
Click the ID of the scaling group in the Scaling Group Name/ID column.
Click Details in the Actions column.
In the upper part of the scaling group details page, click the Rolling Update tab.
Create and execute an image update task.
Click Create Execution Task.
Configure parameters to complete image update.
The following table shows the sample configurations of the task. Configure other parameters based on your business requirements.
Parameter
Example
Task Description
Update multiple images from CentOS 6.4 64-bit to Alibaba Cloud Linux 2.1903 LTS 64-bit at the same time.
Task Type
Update Image
Image for Update
Image-AliyunLinux
Image for Rollback
Image-CentOSBck
Execution Batch
10
Suspension Policy
Without Suspension
Click Create Task.
Read and understand the impacts of the rolling update task and click OK.
Then, the rolling update task is automatically run.
After the task is complete, the images of the 100 ECS instances in the scaling group are updated to Alibaba Cloud Linux 2.1903 LTS 64-bit.
Create and execute a script execution task.
Click Create Execution Task.
Configure parameters to complete task creation.
The following table shows the sample configurations of the task. Configure other parameters based on your business requirements.
Parameter
Example
Task Description
Install Apache and view the status of Apache.
Task Type
Script Execution
Script for Execution
# Install Apache. yum install -y httpd # Start Apache. systemctl start httpd # Enable Apache to run at instance startup. systemctl enable httpd # View the status of Apache. systemctl status httpd
Script for Rollback
# View the status of Apache. systemctl status httpd
Execution Batch
10
Suspension Policy
Without Suspension
Click Create Task.
Read and understand the impacts of the rolling update task and click OK.
Then, the script execution task is automatically run.
After the task is complete, Apache is installed on the 100 ECS instances in the scaling group. Apache is in the active state.