全部產品
Search
文件中心

CloudOps Orchestration Service:ACS-ESS-AdjustScalingGroupInstanceCount

更新時間:Sep 06, 2024

模板名稱

ACS-ESS-AdjustScalingGroupInstanceCount 彈性擴縮容

立即執行

模板描述

通過建立並執行伸縮組規則來調整伸縮組的執行個體數。說明:

  • 如果伸縮組已配置期望執行個體數,當伸縮組內執行個體數不等於期望執行個體數時,Auto Scaling服務會自動進行擴縮容,確保伸縮組內始終保持該數量的執行個體數,執行完畢後請到ESS控制台查看調整結果。

  • 縮容節點後的叢集節點數量,不能小於組件最低節點要求,否則縮容操作可能會返回 code:IncorrectCapacity 的錯誤。

  • 執行請確保您的帳號餘額大於新購執行個體的費用,否則會返回 code:InvalidAccountStatus.NotEnoughBalance 的錯誤。

  • 如果是多可用性區域請擴容可用性區域數的倍數。

  • 擴容的ECS付費方式為隨用隨付,如有需要,客戶需要手動隨用隨付轉訂用帳戶

  • 縮容有兩種方式:縮容指定數量的ECS(伸縮組ECS執行個體調整的數量非0)、從伸縮組中移除指定的ECS(伸縮組ECS執行個體調整的數量為0且選擇要移除的ECS)

  • 縮容數量不能少於伸縮組內最開始開出來的數量。

調整ACK叢集節點池建立節點池。說明:

  • 請仔細閱讀連結文檔並授權角色AliyunOOSLifecycleHook4CSRole。

模板類型

自動化

所有者

Alibaba Cloud

輸入參數

參數名稱

描述

類型

是否必填

預設值

約束

resourceType

將要調整的資源類型

String

ESS

regionId

將要複製的ECS執行個體所在地區

String

{{ ACS::RegionId }}

scalingGroupId

伸縮組ID

String

""

adjustmentType

伸縮規則的調整方式

String

ScaleOut

adjustmentCount

伸縮組ECS執行個體調整的數量

Number

0

instancesToBeRemoved

從伸縮組中移除的ECS執行個體

Json

{'Type': 'ResourceIds', 'ResourceIds': [], 'RegionId': '{{ ACS::RegionId }}'}

clusterId

叢集ID

String

""

nodepoolId

節點池ID

String

""

desiredSize

期望節點數

Number

0

OOSAssumeRole

OOS扮演的RAM角色

String

""

輸出參數

參數名稱

描述

類型

adjustDetail

String

lifecycleHookOOSExecutionResult

String

執行此模板需要的權限原則

{
    "Version": "1",
    "Statement": [
        {
            "Action": [
                "ecs:DescribeInstances"
            ],
            "Resource": "*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "ess:CreateScalingRule",
                "ess:DeleteScalingRule",
                "ess:DescribeScalingActivities",
                "ess:DescribeScalingActivityDetail",
                "ess:ExecuteScalingRule",
                "ess:RemoveInstances"
            ],
            "Resource": "*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "oos:ListExecutions"
            ],
            "Resource": "*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "cs:DescribeClusterNodePoolDetail",
                "cs:ModifyClusterNodePool"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

詳情

ACS-ESS-AdjustScalingGroupInstanceCount詳情

模板內容

FormatVersion: OOS-2019-06-01
Description:
  en: <p class="p">Adjust the number of instances in a scaling group by creating and executing scaling group rules. Description:</p>
    <ul class="ul">
    <li class="li">If the scaling group has been configured with the desired number of instances, when the number of instances in the scaling group is not equal to the expected number of instances, the auto scaling service will automatically scale to ensure that the number of instances in the scaling group is always maintained After the execution is complete, please go to the ESS console to view the adjustment results. </li>
    <li class="li">The number of cluster nodes after scaling down the nodes cannot be less than the minimum node requirements of the component, otherwise the scaling operation may return an error of code:IncorrectCapacity. </li>
    <li class="li">Please ensure that your account balance is greater than the cost of the newly purchased instance, otherwise an error of code:InvalidAccountStatus.NotEnoughBalance will be returned. </li>
    <li class="li">If it is multi-zone, please expand the multiple of the number of zones. </li>
    <li class="li">The payment method for the expanded ECS is pay-as-you-go. If necessary, customers need to Manual subcontracting yearly and monthly. </a></li>
    <li class="li"> There are two ways to scale down:scale down the specified number of ECS (<b>the number of ECS instance adjustments in the scaling group</b> is not 0), remove the specified ECS from the scaling group ( <b>The number of ECS instance adjustments in the scaling group</b> is 0 and the ECS to be removed is selected)</li>
    <li class="li">The scaling cannot be less than the number initially opened in the scaling group. </li>
    </ul>
    <p class="p">Adjust the number of instances in a scaling group by creating and executing scaling group rules. Description:</p>
    <ul class="ul">
    <li class="li">Adjust ACK cluster node pool<a href='https://help.aliyun.com/document_detail/160490.html?spm=5176.2020520152.help.dexternal.253916ddpJbWDl#title-mpp-3jj- oo3'>Expected number of nodes</a>, please read the linked document carefully and authorize the role AliyunOOSLifecycleHook4CSRole. </li>
    </ul>
  zh-cn: <p class="p">通過建立並執行伸縮組規則來調整伸縮組的執行個體數。說明:</p>
    <ul class="ul">
    <li class="li">如果伸縮組已配置期望執行個體數,當伸縮組內執行個體數不等於期望執行個體數時,Auto Scaling服務會自動進行擴縮容,確保伸縮組內始終保持該數量的執行個體數,執行完畢後請到ESS控制台查看調整結果。</li>
    <li class="li">縮容節點後的叢集節點數量,不能小於組件最低節點要求,否則縮容操作可能會返回 code:IncorrectCapacity 的錯誤。</li>
    <li class="li">執行請確保您的帳號餘額大於新購執行個體的費用,否則會返回 code:InvalidAccountStatus.NotEnoughBalance 的錯誤。</li>
    <li class="li">如果是多可用性區域請擴容可用性區域數的倍數。</li>
    <li class="li">擴容的ECS付費方式為隨用隨付,如有需要,客戶需要手動<a href="https://help.aliyun.com/document_detail/49884.html?spm=5176.2020520101.help.dexternal.6ecb4df5sxWQrt">轉訂用帳戶。</a></li>
    <li class="li">縮容有兩種方式:縮容指定數量的ECS(<b>伸縮組ECS執行個體調整的數量</b>非0)、從伸縮組中移除指定的ECS(<b>伸縮組ECS執行個體調整的數量</b>為0且選擇要移除的ECS)</li>
    <li class="li">縮容數量不能少於伸縮組內最開始開出來的數量。</li>
    </ul>
    <p class="p">調整ACK叢集節點池<a href='https://help.aliyun.com/document_detail/160490.html?spm=5176.2020520152.help.dexternal.253916ddpJbWDl#title-mpp-3jj-oo3'>期望節點數</a>。說明:</p>
    <ul class="ul">
    <li class="li">請仔細閱讀連結文檔並授權角色AliyunOOSLifecycleHook4CSRole。</li>
    </ul>
  name-en: Elastic Scaling
  name-zh-cn: 彈性擴縮容
  categories:
    - elastic_manage
    - application_manage
    - computenest
Parameters:
  resourceType:
    Type: String
    Label:
      en: ResourceType
      zh-cn: 將要調整的資源類型
    AllowedValues:
      - ACK
      - ESS
    Default: ESS
  regionId:
    Type: String
    Label:
      en: RegionId
      zh-cn: 將要複製的ECS執行個體所在地區
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  scalingGroupId:
    Type: String
    Label:
      en: ScalingGroupId
      zh-cn: 伸縮組ID
    Default: ''
    AssociationProperty: ALIYUN::ESS::AutoScalingGroup::AutoScalingGroupId
    AssociationPropertyMetadata:
      RegionId: regionId
      Visible:
        Condition:
          Fn::Equals:
            - '${resourceType}'
            - ESS
  adjustmentType:
    Type: String
    Label:
      en: AdjustmentType
      zh-cn: 伸縮規則的調整方式
    AssociationPropertyMetadata:
      LocaleKey: ESSGroupAdjustmentType
      Visible:
        Condition:
          Fn::Equals:
            - '${resourceType}'
            - ESS
    AllowedValues:
      - ScaleOut
      - ScaleIn
      - TotalCapacity
    Default: ScaleOut
  adjustmentCount:
    Type: Number
    Label:
      en: AdjustmentCount
      zh-cn: 伸縮組ECS執行個體調整的數量
    MinValue: 0
    MaxValue: 100
    Default: 0
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Equals:
            - '${resourceType}'
            - ESS
  instancesToBeRemoved:
    Type: Json
    Label:
      en: RemovedInstances
      zh-cn: 從伸縮組中移除的ECS執行個體
    Default:
      Type: ResourceIds
      ResourceIds: []
      RegionId: '{{ ACS::RegionId }}'
    AssociationProperty: Targets
    AssociationPropertyMetadata:
      ResourceType: ALIYUN::ECS::Instance
      RegionId: regionId
      Visible:
        Condition:
          Fn::And:
            - Fn::Equals:
                - '${resourceType}'
                - ESS
            - Fn::Equals:
                - '${adjustmentType}'
                - ScaleIn
            - Fn::Equals:
                - '${adjustmentCount}'
                - 0
  clusterId:
    Label:
      en: ClusterId
      zh-cn: 叢集ID
    Type: String
    Default: ''
    AssociationProperty: ALIYUN::CS::Cluster::ClusterId
    AssociationPropertyMetadata:
      RegionId: ${regionId}
      Visible:
        Condition:
          Fn::Equals:
            - '${resourceType}'
            - ACK
  nodepoolId:
    Label:
      en: NodepoolId
      zh-cn: 節點池ID
    Type: String
    Default: ''
    AssociationProperty: ALIYUN::CS::Cluster::ClusterNodePool
    AssociationPropertyMetadata:
      RegionId: ${regionId}
      ClusterId: ${clusterId}
      Visible:
        Condition:
          Fn::Equals:
            - '${resourceType}'
            - ACK
  desiredSize:
    Label:
      en: DesiredSize
      zh-cn: 期望節點數
    Type: Number
    MinValue: 0
    MaxValue: 100
    Default: 0
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Equals:
            - '${resourceType}'
            - ACK
  OOSAssumeRole:
    Label:
      en: OOSAssumeRole
      zh-cn: OOS扮演的RAM角色
    Type: String
    Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
  - Name: chooseNextTaskByResourceType
    Action: 'ACS::Choice'
    Description:
      en: Choose next task by resource type
      zh-cn: 根據資源類型選擇下一個任務
    Properties:
      DefaultTask: whetherToRemoveInstancesFromScalingGroup
      Choices:
        - When:
            Fn::Equals:
              - 'ACK'
              - '{{ resourceType }}'
          NextTask: getNodePoolDetail
  - Name: whetherToRemoveInstancesFromScalingGroup
    Action: 'ACS::Choice'
    Description:
      en: Choose next task by adjustment type
      zh-cn: 根據伸縮規則調整方式選擇下一個任務
    Properties:
      DefaultTask: createScalingRule
      Choices:
        - When:
            Fn::And:
              - Fn::Equals:
                  - '{{adjustmentType}}'
                  - ScaleIn
              - Fn::Equals:
                  - '{{adjustmentCount}}'
                  - 0
          NextTask: getInstanceToBeRemoved
  - Name: getInstanceToBeRemoved
    Description:
      en: Get the ECS instance to be removed
      zh-cn: 擷取待移除的ECS執行個體
    Action: ACS::SelectTargets
    Properties:
      ResourceType: ALIYUN::ECS::Instance
      RegionId: '{{ regionId }}'
      Filters:
        - '{{ instancesToBeRemoved }}'
    Outputs:
      instanceIds:
        Type: List
        ValueSelector: Instances.Instance[].InstanceId
  - Name: removeInstances
    Action: 'ACS::ExecuteAPI'
    OnSuccess: waitScalingActivityComplete
    When:
      Fn::Not:
        Fn::Equals:
          - '{{ getInstanceToBeRemoved.instanceIds }}'
          - []
    Description:
      en: Remove instances from scaling group
      zh-cn: 從伸縮組中移除ECS執行個體
    Properties:
      Service: ESS
      API: RemoveInstances
      Parameters:
        RegionId: '{{ regionId }}'
        ScalingGroupId: '{{ scalingGroupId }}'
        InstanceIds: '{{ getInstanceToBeRemoved.instanceIds }}'
    Outputs:
      scalingActivityId:
        Type: String
        ValueSelector: .ScalingActivityId
  - Name: createScalingRule
    Action: 'ACS::ExecuteAPI'
    Description:
      en: Create a ScalingRule
      zh-cn: 建立伸縮規則
    Properties:
      Service: ESS
      API: CreateScalingRule
      Parameters:
        RegionId: '{{ regionId }}'
        ScalingGroupId: '{{ scalingGroupId }}'
        ScalingRuleName: '{{ ACS::ExecutionId }}'
        AdjustmentType:
          Fn::If:
            - Fn::Equals:
                - 'TotalCapacity'
                - '{{ adjustmentType }}'
            - TotalCapacity
            - QuantityChangeInCapacity
        AdjustmentValue:
          Fn::If:
            - Fn::Equals:
                - ScaleIn
                - '{{ adjustmentType }}'
            - '-{{ adjustmentCount }}'
            - '{{ adjustmentCount }}'
    Outputs:
      scalingRuleAri:
        Type: String
        ValueSelector: ScalingRuleAri
      scalingRuleId:
        Type: String
        ValueSelector: ScalingRuleId
  - Name: executeScalingRule
    Description:
      en: Execute the ScalingRule
      zh-cn: 執行伸縮規則
    OnError: deleteScalingRule
    Action: 'ACS::ExecuteApi'
    Properties:
      Service: ESS
      API: ExecuteScalingRule
      Parameters:
        RegionId: '{{ regionId }}'
        ScalingRuleAri: '{{ createScalingRule.scalingRuleAri }}'
    Outputs:
      scalingActivityId:
        Type: String
        ValueSelector: ScalingActivityId
  - Name: waitScalingActivityComplete
    Description:
      en: Poll scaling activity execution until success or failure
      zh-cn: 輪詢伸縮活動執行情況直到成功或者失敗
    OnError: deleteScalingRule
    Retries: 30
    Action: 'ACS::WaitFor'
    Properties:
      Service: ESS
      API: DescribeScalingActivities
      Parameters:
        RegionId: '{{ regionId }}'
        ScalingActivityId1:
          Fn::If:
            - Fn::And:
                - Fn::Equals:
                    - '{{adjustmentType}}'
                    - ScaleIn
                - Fn::Equals:
                    - '{{adjustmentCount}}'
                    - 0
            - '{{ removeInstances.scalingActivityId }}'
            - '{{ executeScalingRule.scalingActivityId }}'
      DesiredValues:
        - Successful
      StopRetryValues:
        - Failed
        - Rejected
        - Warning
      PropertySelector: 'ScalingActivities.ScalingActivity[0].StatusCode'
  - Name: deleteScalingRule
    When:
      Fn::Not:
        Fn::And:
          - Fn::Equals:
              - '{{adjustmentType}}'
              - ScaleIn
          - Fn::Equals:
              - '{{adjustmentCount}}'
              - 0
    Description:
      en: Delete ScalingRule
      zh-cn: 刪除伸縮組規則
    Action: 'ACS::ExecuteApi'
    Properties:
      Service: ESS
      API: DeleteScalingRule
      Parameters:
        RegionId: '{{ regionId }}'
        ScalingRuleId: '{{ createScalingRule.scalingRuleId }}'
  - Name: describeScalingActivityDetail
    Description:
      en: Describe scaling activity detail
      zh-cn: 查詢一個伸縮活動的詳細資料
    Action: 'ACS::ExecuteApi'
    Properties:
      Service: ESS
      API: DescribeScalingActivityDetail
      Parameters:
        RegionId: '{{ regionId }}'
        ScalingActivityId:
          Fn::If:
            - Fn::And:
                - Fn::Equals:
                    - '{{adjustmentType}}'
                    - ScaleIn
                - Fn::Equals:
                    - '{{adjustmentCount}}'
                    - 0
            - '{{ removeInstances.scalingActivityId }}'
            - '{{ executeScalingRule.scalingActivityId }}'
    Outputs:
      detail:
        Type: String
        ValueSelector: .Detail
  - Name: getOOSExecutionOutput
    Action: 'ACS::ExecuteAPI'
    OnSuccess: ACS::END
    Description:
      en: Get the lifecycle hook OOS execution output
      zh-cn: 擷取生命週期掛鈎OOS執行的輸出
    Properties:
      Service: OOS
      API: ListExecutions
      Parameters:
        RegionId: '{{ regionId }}'
        Tags:
          ESS:ScalingActivityId:
            Fn::If:
              - Fn::And:
                  - Fn::Equals:
                      - '{{adjustmentType}}'
                      - ScaleIn
                  - Fn::Equals:
                      - '{{adjustmentCount}}'
                      - 0
              - '{{ removeInstances.scalingActivityId }}'
              - '{{ executeScalingRule.scalingActivityId }}'
    Outputs:
      lifecycleHookOOSExecutionResult:
        Type: String
        ValueSelector: 'Executions[].Outputs'
  - Name: getNodePoolDetail
    Action: ACS::WaitFor
    Description:
      en: Get cluster node pool info
      zh-cn: 擷取叢集節點池資訊
    Retries: 20
    Properties:
      Service: CS
      API: DescribeClusterNodePoolDetail
      Method: GET
      URI: /clusters/{{clusterId}}/nodepools/{{nodepoolId}}
      Parameters: {}
      DesiredValues:
        - active
      PropertySelector: .status.state
    Outputs:
      nodePoolInfo:
        Type: Json
        ValueSelector: .
  - Name: modifyClusterNodePool
    Action: ACS::ExecuteAPI
    Description:
      en: Modify cluster node pool configuration
      zh-cn: 修改叢集節點池配置
    Properties:
      Service: CS
      API: ModifyClusterNodePool
      Method: PUT
      Headers:
        Content-Type: application/json
      URI: /clusters/{{clusterId}}/nodepools/{{nodepoolId}}
      Body:
        Fn::Jq:
          - First
          - '.+({"scaling_group": (.scaling_group + {"desired_size": {{desiredSize}}})}) | del(.scaling_group.login_password)'
          - '{{ getNodePoolDetail.nodePoolInfo }}'
  - Name: untilClusterNodePoolReady
    Action: ACS::WaitFor
    Description:
      en: Wait for the cluster node pool configuration to complete
      zh-cn: 等待叢集節點池配置修改完成
    Retries: 20
    Properties:
      Service: CS
      API: DescribeClusterNodePoolDetail
      Method: GET
      Parameters: {}
      URI: /clusters/{{clusterId}}/nodepools/{{nodepoolId}}
      DesiredValues:
        - active
      PropertySelector: .status.state
Outputs:
  adjustDetail:
    Type: String
    Value: '{{ describeScalingActivityDetail.detail }}'
  lifecycleHookOOSExecutionResult:
    Type: String
    Value: '{{ getOOSExecutionOutput.lifecycleHookOOSExecutionResult }}'
Metadata:
  ALIYUN::OOS::Interface:
    ParameterGroups:
      - Parameters:
          - regionId
          - resourceType
          - scalingGroupId
          - adjustmentType
          - adjustmentCount
          - instancesToBeRemoved
          - clusterId
          - nodepoolId
          - desiredSize
        Label:
          default:
            zh-cn: 調整方式設定
            en: Scaling Rule Configure Parameters
      - Parameters:
          - OOSAssumeRole
        Label:
          default:
            zh-cn: 進階選項
            en: Control Options