This topic describes how to set rules for hostnames in a scaling configuration to generate sequential and unique hostnames for ECS instances during scale-out events. This helps you manage ECS instances in a more efficient manner.
Background information
- If you want to make the hostnames of ECS instances in a scaling group sequential and
unique, you must set rules for the hostnames in a scaling configuration instead of
in a launch template. For more information, see (Recommended) Sorting at a fixed-value increment and Dynamic sorting based on extended sequential values.
Note The hostnames of ECS instances in a scaling group are sequentially generated but not necessarily consecutive. For example, the hostnames of created ECS instances in a scaling group are ess-node-0999, ess-node-1000, and ess-node-1002. This indicates that the ess-node-1001 ECS instance fails to start normally. Auto Scaling considers this instance unhealthy, removes it from the scaling group, and then creates another instance whose hostname is ess-node-1002.
- If you want to make the hostnames of only ECS instances that are created during a single scale-out event sequential and unique, you can set the hostnames based on the specified sorting rule. For more information, see Batch configure sequential names or hostnames for multiple instances.
- If you have no naming requirements for hostnames, you can use regular hostnames without the need to set hostnames based on the preceding rules. For example, if you set the hostname to hostname for a scaling group, the hostnames of all created ECS instances in the scaling group are hostname.
In this topic, two example scenarios are used to describe how to set rules for generating sequential and unique hostnames by using the Auto Scaling console and by calling API operations.
Scenario 1: Set sequential and unique hostnames in the console
Scenario 2: Set sequential and unique hostnames by calling API operations
(Recommended) Sorting at a fixed-value increment
Hostnames are in the name_prefix(AUTO_INCREMENT)[begin_number,bits]name_suffix format.
Segment | Required | Description | Example |
---|---|---|---|
name_prefix | Yes | The prefix of the hostname. | ess-node- |
(AUTO_INCREMENT) | Yes | The fixed value used to indicate the sorting method. | (AUTO_INCREMENT) |
[begin_number,bits] | Yes | The sequential value of the hostname. After this segment is specified, the sequential
values of hostnames are incremented.
Note By default, the system sequentially increments the values. If a created ECS instance
in a scaling group cannot be started, Auto Scaling removes the instance from the scaling
group and creates another instance. Therefore, the hostnames of ECS instances in the
scaling group may not be consecutively incremented.
Note We recommend that you set bits to at least 3. Otherwise, the upper limit of the sequential values may be reached in a short period
of time. If Auto Scaling needs to create more ECS instances after the upper limit
is reached, an error is reported and the scale-out event is suspended. In this case,
you must set the rules for generating hostnames again.
The [begin_number,bits] segment cannot contain spaces. By default, when the number of digits of the specified begin_number value is greater than the bits value, bits is set to 6. |
[0,6] |
name_suffix | No | The suffix of the instance name or hostname. | -ecshost |
Example | Existing hostname with the maximum sequential value in a scaling group | Hostname (three created ECS instances) | Description |
---|---|---|---|
ess-node-(AUTO_INCREMENT)[0,3]-ecshost | N/A | ess-node-000-ecshost, ess-node-001-ecshost, and ess-node-002-ecshost. | The number of digits of all sequential values is the bits value. When Auto Scaling creates instances in a scaling group for the first time, the sequential value starts from the begin_number value and sequentially increments based on the number of created instances. |
|
N/A | ess-node-000000-ecshost, ess-node-000001-ecshost, and ess-node-000002-ecshost. | If begin_number is not specified, begin_number is set to 0. If bits is not specified, bits is set to 6. |
ess-node-(AUTO_INCREMENT)[99,1]-ecshost | ess-node-000099-ecshost | ess-node-000100-ecshost, ess-node-000101-ecshost, and ess-node-000102-ecshost. |
|
ess-node-(AUTO_INCREMENT)[0,2]-ecshost | ess-node-99-ecshost | An error is reported and the scale-out event is suspended. |
|
ess-node-(AUTO_INCREMENT)[0,4] | ess-node-0998-ecshost | ess-node-0999, ess-node-1000, and ess-node-1002. |
|
Dynamic sorting based on extended sequential values
Hostnames are in the name_prefix(ess_extend_begin,ess_extend_bits)[begin_number,bits]name_suffix format.
Segment | Required | Description | Example |
---|---|---|---|
name_prefix | Yes | The prefix of the hostname. | ess-node- |
(ess_extend_begin,ess_extend_bits) | Yes | The extended sequential value of the hostname. When the base sequential value of existing
hostnames in a scaling group is equal to the maximum sequential value, one value is
added to the extended sequential value. Then, the base sequential value increments
from 0 again until the upper limit is reached.
Notice If Auto Scaling needs to create more ECS instances after the upper limits of extended
sequential values and base sequential values are both reached, an error is reported
and the scale-out event is suspended. In this case, you must set the rules for generating
hostnames again.
The (ess_extend_begin,ess_extend_bits) segment cannot contain spaces. By default, when the number of digits of the specified ess_extend_begin value is greater than the bits value, bits is set to 3. |
(0,3) |
[begin_number,bits] | Yes | The base sequential value of the hostname. After this segment is specified, the base
sequential values of hostnames are incremented to the maximum value. Then, one value
is added to the extended sequential value and the base sequential value increments
from 0 again until the upper limit is reached.
Notice By default, the system sequentially increments the values. If a created ECS instance
in a scaling group cannot be started, Auto Scaling removes the instance from the scaling
group and creates another instance. Therefore, the hostnames of ECS instances in the
scaling group may not be consecutively incremented.
Notice
The [begin_number,bits] segment cannot contain spaces. By default, when the number of digits of the specified begin_number value is greater than the bits value, bits is set to 6. |
[0,6] |
name_suffix | No | The suffix of the instance name or hostname. | -ecshost |
Example | Existing hostname with the maximum sequential value in a scaling group | Hostname (three created ECS instances) | Description |
---|---|---|---|
ess-node-(0,3)[0,3]-ecshost | N/A | ess-node-000000-ecshost, ess-node-000001-ecshost, and ess-node-000002-ecshost. | When Auto Scaling creates instances in a scaling group for the first time, the sequential
values for hostnames of the instances are set based on the following rules:
|
|
N/A | ess-node-000000000-ecshost, ess-node-000000001-ecshost, and ess-node-000000002-ecshost. |
|
ess-node-(0,1)[0,1]-ecshost | ess-node-08-ecshost | ess-node-10-ecshost, ess-node-11-ecshost, and ess-node-12-ecshost. |
|
ess-node-(0,1)[0,1]-ecshost | ess-node-Z9-ecshost | An error is reported and the scale-out event is suspended. |
|
ess-node-(0,1)[0,3] | ess-node-0099-ecshost | ess-node-0100, ess-node-0101, and ess-node-0103. |
|
ess-node-(0,1)[99,1]-ecshost | ess-node-0000099-ecshost | ess-node-0000100-ecshost, ess-node-0000101-ecshost, and ess-node-0000102-ecshost. |
|