首页 > 解决方案 > 如何缩小 AutoScalingGroup 中的特定实例?

问题描述

我正在使用 Heat 来实现自动缩放,下面是我的代码的一小部分:

heat_template_version: 2016-10-14
...

resources:
    corey_server_group:
        type: OS::Heat::AutoScalingGroup
        depends_on: corey-server
        properties:
            min_size: 1
            max_size: 5
            resource:
                type: CoreyLBSServer.yaml
                properties:
......

CoreyLBSServer.yaml

heat_template_version: 2016-10-14
...

resources:
    server:
    type: OS::Nova::Server
    properties:
        flavor:
......

我正在寻找一种缩小特定实例的方法,这是我尝试过的一些方法,但都没有奏效,它总是缩小最旧的实例。

1.关闭实例,然后发出缩减策略信号。(X) 2.据此,从attribute中找到stack-id ,将resource标记为,然后发出
scaledown policy。(X) 3.从attribute中找到stack-id ,设置stack status为,然后signal scaledown policy。(X)refs_mapserverunhealthy
refs_mapFAILED

我试图找出 AutoScalingGroup 在缩减时使用什么策略,从代码heat/common/grouputils.py中,它按“created_time”然后按名称对成员进行排序,因此在缩减时将首先删除最旧的成员。但是有一个例外,如果include_failed设置了,失败的成员将首先放入按 created_time 排序的列表中,然后按 name 排序

更新

我终于成功地将我的目标设置为“失败”,这是命令:

# firstly, print the physical_resource_id of corey_server_group
openstack stack resource show -c physical_resource_id <parent_stack_id> corey_server_group

# secondly, list resources in the corey_server_group
openstack stack resource list <physical_resource_id>

# thirdly, mark the target as unhealthy  
openstack stack resource mark unhealthy <physical_resource_id> <resource_name>

# after these commands, you will see the resource_status of the target becomes "Check Failed"

但它还有另一个问题,Heat 在缩减的同时会删除“失败”和“最旧”的资源!如何仅缩小“标记为失败”的目标?

标签: openstackautoscalingopenstack-heat

解决方案


经过几天的跟踪,我终于找到了一种方法来缩小 AutoScalingGroup 中的特定实例。

我们先看一下源码:heat/common/grouputils.py#L114

首先按 created_time 然后按名称对实例列表进行排序。如果设置了 include_failed,失败的成员将首先放在按 created_time 排序的列表中,然后按名称排序。

如您所见,默认include_failed设置为False,因此不健康的成员不会包含在列表中,这就是我的问题中描述的过程不起作用的原因。

如果要启用缩小特定实例的功能,则必须include_failed=True在调用函数时显式定义,以下是我的部分代码:

热/引擎/资源/aws/autoscaling/autoscaling_group.py 在此处输入图像描述

因为我使用的是 AutoScalingGroup,我需要修改两个文件:
heat/engine/resources/aws/
autoscaling/autoscaling_group.py heat/engine/resources/openstack/heat/autoscaling_group.py

重新启动 Heat 服务,然后您可以将目标标记为不健康,并向策略发出信号以缩减特定实例:

openstack stack resource mark unhealthy <physical_resource_id> <resource_name>
openstack stack resource signal <parent_stack_id> your_scaledown_policy

仅供参考,该表显示FalseTrue(scaling_adjustment=1) 之间的不同行为。

                   | include_failed=False (default) | include_failed=True  
                   |                                |
Scale Up           | Add one instance               | Add one instance
                   |                                |
Scale down         | Remove the oldest              | Remove the oldest
                   |                                |
Stack Update       | Nothing changed                | Nothing changed
                   |                                |
Unhealthy + Up     | Add one & remove unhealthy     | Add one & fix unhealthy
                   |                                |
Unhealthy + Down   | Remove one & remove unhealthy  | Remove the unhealthy one
                   |                                |
Unhealthy + Update | Fix unhealthy                  | Fix unhealthy

推荐阅读