OOS简介
Operation Orchestration Service,简称OOS,是全面、免费的云上自动化运维平台,提供运维任务的管理和执行。典型使用场景包括:事件驱动运维,批量操作运维,定时运维任务,跨地域运维等,OOS为重要运维场景提供审批,通知等功能。OOS帮您实现标准化运维任务,从而实践运维即代码(Operations as Code)的先进理念。关于OOS更详细的介绍请参见什么是运维编排服务。
ESS简介
使用弹性伸缩(Auto Scaling),您可以根据业务需求和策略设置伸缩规则,在业务需求增长时自动为您增加ECS实例以保证计算能力,在业务需求下降时自动减少ECS实例以节约成本。弹性伸缩不仅适合业务量不断波动的应用程序,同时也适合业务量稳定的应用程序。关于ESS更详细的介绍请参见什么是弹性伸缩。
场景介绍
ESS生命周期挂钩使用OOS模板实现自动绑定账户下已有EIP到实例。
操作步骤
1.登陆OOS控制台,找到我的模板,点击创建模板。
2.选择空白模版。
3.复制下文提供的模板到YAML栏中,输入模板名称(ECS-DescribeAndAssociateEipAddress),点击创建模板。
ECS-DescribeAndAssociateEipAddress内容:
FormatVersion: OOS-2019-06-01
Description: Attach eip to instance.
Parameters:
regionId:
Description: The ID of region.
Type: String
Default: '{{ ACS::RegionId }}'
instanceId:
Description: The id Instance.
Type: String
instanceType:
Description: The type of instance.
Type: String
AllowedValues:
- Nat
- SlbInstance
- EcsInstance
- NetworkInterface
- HaVip
Default: EcsInstance
Tasks:
- Name: describeEipAddresses
Action: 'ACS::ExecuteApi'
Description: Views the eip attr.
Properties:
Service: VPC
API: DescribeEipAddresses
Parameters:
RegionId: '{{ regionId }}'
Status: Available
Outputs:
allocationId:
Type: String
ValueSelector: 'EipAddresses.EipAddress[].AllocationId'
- Name: AssociateEipAddress
Action: 'ACS::ExecuteAPI'
Description: Associate Eip address to instance.
Properties:
Service: VPC
API: AssociateEipAddress
Parameters:
RegionId: '{{ regionId }}'
AllocationId: '{{ describeEipAddresses.allocationId }}'
InstanceId: '{{ instanceId }}'
InstanceType: '{{ instanceType }}'
4.重复以上步骤,创建模板ESS-LifeCycleDescribeAndAssociateEipAddress。
ESS-LifeCycleDescribeAndAssociateEipAddress内容:
FormatVersion: OOS-2019-06-01
Description:
en: Use lifecycleHook to get available EIP and attach them to the instance(only supports elastic expansion activities).
zh-cn: 使用生命周期挂钩获取可用弹性IP并将其绑定到实例(仅支持弹性扩张活动)。
name-en: ESS-LifeCycleDescribeAndAssociateEipAddress
name-zh-cn: 使用生命周期挂钩绑定EIP到实例
categories:
- elastic_manage
Parameters:
regionId:
Description:
name-en: regionId
name-zh-cn: 地域ID
en: The ID of region.
zh-cn: '地域ID,请使用弹性伸缩系统默认值 ${regionId}'
Type: String
Default: '${regionId}'
instanceIds:
Description:
name-en: instanceIds
name-zh-cn: ECS实例ID列表
en: The ID list of the ECS instance.
zh-cn: 'ECS实例ID列表,请使用弹性伸缩系统默认值 ["${instanceId}"]'
Type: List
Default:
- '${instanceIds}'
lifecycleHookId:
Description:
name-en: lifecycleHookId
name-zh-cn: 生命周期挂钩ID
en: The ID of the lifecycle hook.
zh-cn: '生命周期挂钩ID,请使用弹性伸缩系统默认值 ${lifecycleHookId}'
Type: String
Default: '${lifecycleHookId}'
lifecycleActionToken:
Description:
name-en: lifecycleActionToken
name-zh-cn: 实例关联的特定伸缩活动的令牌
en: The token that indicates a specific scaling activity associated with an instance.
zh-cn: '实例关联的特定伸缩活动的令牌,请使用弹性伸缩系统默认值 ${lifecycleActionToken}'
Type: String
Default: '${lifecycleActionToken}'
rateControl:
Description:
name-en: rateControl
name-zh-cn: 速率控制
en: Concurrency ratio of task execution.
zh-cn: 任务执行的并发比率。
Type: Json
AssociationProperty: RateControl
Default:
Mode: Concurrency
MaxErrors: 0
Concurrency: 1
OOSAssumeRole:
Description:
name-en: OOSAssumeRole
name-zh-cn: OOS扮演的RAM角色
en: The RAM role to be assumed by OOS.
zh-cn: OOS扮演的RAM角色。
Type: String
Default: OOSServiceRole
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: describeAndAssociateEipAddress
Action: 'ACS::Template'
OnSuccess: CompleteLifecycleActionForContinue
OnError: CompleteLifecycleActionForAbandon
Description:
en: Views available eip and attach to instace.
zh-cn: 获取账户下可用EIP并绑定到实例上。
Properties:
TemplateName: ECS-DescribeAndAssociateEipAddress
Parameters:
regionId: '{{ regionId }}'
instanceId: '{{ ACS::TaskLoopItem }}'
instanceType: 'EcsInstance'
Loop:
RateControl: '{{ rateControl }}'
Items: '{{ instanceIds }}'
- Name: CompleteLifecycleActionForContinue
Action: 'ACS::ExecuteAPI'
Description:
en: Modify lifecycle action for continue.
zh-cn: 修改伸缩活动的等待状态为继续完成。
OnSuccess: 'ACS::END'
Properties:
Service: ESS
API: CompleteLifecycleAction
Parameters:
RegionId: '{{ regionId }}'
LifecycleHookId: '{{ lifecycleHookId }}'
LifecycleActionToken: '{{ lifecycleActionToken }}'
LifecycleActionResult: CONTINUE
- Name: CompleteLifecycleActionForAbandon
Action: 'ACS::ExecuteAPI'
Description:
en: Complete lifecycle action for Abandon.
zh-cn: 修改伸缩活动的等待状态为弃用。
Properties:
Service: ESS
API: CompleteLifecycleAction
Parameters:
RegionId: '{{ regionId }}'
LifecycleHookId: '{{ lifecycleHookId }}'
LifecycleActionToken: '{{ lifecycleActionToken }}'
LifecycleActionResult: ABANDON
5.登陆ESS控制台,在目标伸缩组生命周期栏新建生命周期挂钩。
6.配置生命周期挂钩参数,设置参数(本模板使用默认参数即可),单击确认。
7.创建弹性扩张类型的规则,执行规则,弹出的实例会自动挂载EIP。注意:当账号下EIP不足时弹性扩张活动会失败。