This topic describes how to configure naming rules in a scaling configuration. These rules generate sequential and unique instance names or hostnames for ECS instances added during a scale-out, which simplifies instance management.
Background
A scaling group can add one or more ECS instances during a single scale-out or across multiple scale-outs. You can configure naming rules for instance names or hostnames in either a scaling configuration or a launch template.
The methods for setting instance name or hostname rules vary by scenario, as shown in the following table. This topic covers only Scenario 1.
Scenario
Solution
References
Scenario 1: All scaled-out ECS instances in a scaling group must have sequential and unique instance names or hostnames.
You must configure the instance name or hostname rules in the scaling configuration. You cannot use a launch template for this configuration.
ImportantThe instance names or hostnames in a scaling group increase sequentially, but they are not guaranteed to increase consecutively. For example, if the hostnames created during a scale-out are
ess-node-0999,ess-node-1000, andess-node-1002, this indicates that the ECS instance with the hostnameess-node-1001failed to start. The scaling group considers this instance unhealthy, removes it, and then creates a new ECS instance, assigning it the next available hostname,ess-node-1002.Scenario 2: The instance names or hostnames of ECS instances are unique and sequential for each scale-out event, but are not required to be unique across all instances in the scaling group.
Use the specified sorting rule to configure the names.
Scenario 3: You have no requirements for the instance names or hostnames of the scaled-out ECS instances.
You do not need to configure naming rules as described in Scenario 1 or 2. You can set a static name.
For example, if you set the hostname to
hostname, all scaled-out ECS instances will have the hostnamehostname.None
Method 1: By console
Create a scaling group.
For more information, see Create a scaling group.
Create a scaling configuration and enable it.
For more information, see Create a scaling configuration for ECS instances. In the Advanced Settings section, specify the naming rules for Instance Name and Host.
For example, set Instance Name to
ess-node-(AUTO_INCREMENT)[0,3], and set Host toess-node-(AUTO_INCREMENT)[0,3]-ecshost.NoteThe naming rule used in this example is increment by fixed value. For more information, see (Recommended) Increment by fixed value. If you want to generate instance names or hostnames based on dynamic sorting rules, see Dynamic sorting by extended sequential value.
Enable the scaling group.
For more information, see Enable a scaling group.
Create and execute a scaling rule.
Create a scaling rule.
For more information, see Create a scaling rule.
This example uses a simple rule. When the scaling rule is executed, three ECS instances are added to the scaling group.
Execute the scaling rule.
For more information, see Execute a scaling rule.
After the scaling activity succeeds, the instance names and hostnames of the three new ECS instances are as follows:
Instance names: ess-node-000, ess-node-001, ess-node-002
Hostnames: ess-node-000-ecshost, ess-node-001-ecshost, ess-node-002-ecshost
Method 2: By API
Call the CreateScalingGroup API operation to create a scaling group.
For more information, see CreateScalingGroup.
Call the CreateScalingConfiguration API operation to create a scaling configuration.
For more information, see CreateScalingConfiguration. In the Request Parameters, you must set the InstanceName and HostName parameters.
For example, set InstanceName to
ess-node-(AUTO_INCREMENT)[0,3]and HostName toess-node-(AUTO_INCREMENT)[0,3]-ecshost.NoteThe naming rule used in this example is increment by fixed value. For more information, see (Recommended) Increment by fixed value. If you want to generate instance names or hostnames based on dynamic sorting rules, see Dynamic sorting by extended sequential value.
Call the EnableScalingGroup API operation to enable the scaling group.
For more information, see EnableScalingGroup.
Create and execute a scaling rule.
Call the CreateScalingRule API operation to create a scaling rule.
For more information, see CreateScalingRule.
This example uses a simple rule. When the scaling rule is executed, three ECS instances are added to the scaling group.
Call the ExecuteScalingRule API operation to execute the scaling rule.
For more information, see ExecuteScalingRule.
After the rule is executed, the three new ECS instances have the following instance names and hostnames:
Instance names: ess-node-000, ess-node-001, ess-node-002
Hostnames: ess-node-000-ecshost, ess-node-001-ecshost, ess-node-002-ecshost
(Recommended) Fixed increment sorting
The parameter format is name_prefix(AUTO_INCREMENT)[begin_number,bits]name_suffix.
The rules and logic for instance names and hostnames are identical. This section uses hostname rules as an example.
Table 1. Parameters
Field | Required | Description | Example |
name_prefix | Yes | The prefix of the hostname. | ess-node- |
(AUTO_INCREMENT) | Yes | A fixed value that identifies this sorting method. | (AUTO_INCREMENT) |
[begin_number,bits] | Yes | Specifies the sequential number for the hostname. After this parameter is set, the sequential number of the hostname increments. Important The [begin_number,bits] field cannot contain spaces. The number increases sequentially by default. However, if a new instance fails to start, the scaling group removes it and creates a replacement. This can result in non-consecutive hostnames (intermittent increments).
Note We recommend setting bits to at least 3 to avoid reaching the upper limit too quickly. If the limit is reached, scaling activities will fail until you reconfigure the naming rule. | [0,6] |
name_suffix | No | The suffix of the hostname. | -ecshost |
Table 2. Parameter examples
Naming example | Maximum existing value | New hostnames | Description |
ess-node-(AUTO_INCREMENT)[0,3]-ecshost | None | ess-node-000-ecshost, ess-node-001-ecshost, ess-node-002-ecshost | During the first scale-out, the number of digits in the sequential number is the value of bits. The sequential number starts from the value of begin_number and increments for each ECS instance added. |
| None | ess-node-000000-ecshost, ess-node-000001-ecshost, ess-node-000002-ecshost | If you do not configure begin_number or bits, begin_number defaults to 0 and bits defaults to 6. |
ess-node-(AUTO_INCREMENT)[99,1]-ecshost | ess-node-000099-ecshost | ess-node-000100-ecshost, ess-node-000101-ecshost, ess-node-000102-ecshost |
|
ess-node-(AUTO_INCREMENT)[0,2]-ecshost | ess-node-99-ecshost | The scaling activity reports an error and stops. |
|
ess-node-(AUTO_INCREMENT)[0,4] | ess-node-0998 | ess-node-0999, ess-node-1000, ess-node-1002 |
|
Dynamic extension sorting
The parameter format is name_prefix(ess_extend_begin,ess_extend_bits)[begin_number,bits]name_suffix.
The rules and logic for instance names and hostnames are identical. This section uses hostname rules as an example.
Table 3. Parameters
Field | Required | Description | Example |
name_prefix | Yes | The prefix of the hostname. | ess-node- |
(ess_extend_begin,ess_extend_bits) | Yes | Specifies the extended sequential number for the hostname. When the base sequential number of an existing hostname in the scaling group reaches its maximum value, this parameter is incremented by one, and the base sequential number restarts from 0. This cycle continues until the upper limit is reached.
Important If both the extended and base sequential numbers reach their upper limits, scaling activities will fail. You must then reconfigure the naming rule. The (ess_extend_begin,ess_extend_bits) field cannot contain spaces. If the number of digits in the specified ess_extend_begin is greater than the value of bits, bits defaults to 3. | (0,3) |
[begin_number,bits] | Yes | Specifies the base sequential number for the hostname. This parameter increments to its maximum value. On the next scale-out, the extended parameter is incremented by one, and this parameter restarts from 0. This cycle continues until the upper limit is reached. Important The system increases the value sequentially by default. However, if a scaled-out ECS instance fails to start, the scaling group removes it and then creates a new ECS instance. As a result, hostnames of ECS instances within the scaling group may increase intermittently.
Important
The [begin_number,bits] field cannot contain spaces. If the number of digits in the specified begin_number is greater than the value of bits, bits defaults to 6. | [0,6] |
name_suffix | No | The suffix of the hostname. | -ecshost |
Table 4. Parameter examples
Naming example | Maximum existing value | New hostnames | Description |
ess-node-(0,3)[0,3]-ecshost | None | ess-node-000000-ecshost, ess-node-000001-ecshost, ess-node-000002-ecshost | For the first scale-out:
|
| None | ess-node-000000000-ecshost, ess-node-000000001-ecshost, ess-node-000000002-ecshost |
|
ess-node-(0,1)[0,1]-ecshost | ess-node-08-ecshost | ess-node-10-ecshost, ess-node-11-ecshost, ess-node-12-ecshost |
|
ess-node-(0,1)[0,1]-ecshost | ess-node-Z9-ecshost | The scaling activity reports an error and stops. |
|
ess-node-(0,1)[0,3] | ess-node-0099 | ess-node-0100, ess-node-0101, ess-node-0103 |
|
ess-node-(0,1)[99,1]-ecshost | ess-node-0000099-ecshost | ess-node-0000100-ecshost, ess-node-0000101-ecshost, ess-node-0000102-ecshost |
|