ALIYUN::CS::ClusterNodePool

更新时间:
复制 MD 格式

ALIYUN::CS::ClusterNodePool类型用于为集群创建节点池。

语法

{
  "Type": "ALIYUN::CS::ClusterNodePool",
  "Properties": {
    "TeeConfig": Map,
    "ClusterId": String,
    "NodePoolInfo": Map,
    "KubernetesConfig": Map,
    "Count": Integer,
    "Management": Map,
    "AutoScaling": Map,
    "ScalingGroup": Map
  }
}

属性

属性名称

类型

必须

允许更新

描述

约束

ClusterId

String

是

否

集群ID。

您可以通过调用DescribeClustersV1查询集群ID。

ScalingGroup

Map

是

是

节点池扩容组配置。

您可以通过调用DescribeClusterNodePools查询节点池扩容组配置。

更多信息,请参见ScalingGroup语法和ScalingGroup属性。

AutoScaling

Map

否

否

自动伸缩配置。

更多信息,请参见AutoScaling语法和AutoScaling属性。

Count

Integer

否

是

节点池节点数量。

无

KubernetesConfig

Map

否

是

集群相关配置。

更多信息,请参见KubernetesConfig语法和KubernetesConfig属性。

Management

Map

否

否

托管节点池配置。

更多信息,请参见Management语法和Management属性。

NodePoolInfo

Map

否

否

节点池配置。

更多信息,请参见NodePoolInfo语法和NodePoolInfo属性。

TeeConfig

Map

否

否

加密计算集群配置。

更多信息,请参见TeeConfig语法和TeeConfig属性。

TeeConfig语法

"TeeConfig": {
  "TeeEnable": Boolean
}

TeeConfig属性

属性名称

类型

必须

允许更新

描述

约束

TeeEnable

Boolean

是

否

是否开启加密计算集群。

取值:

  • true:开启加密计算集群。

  • false(默认值):不开启加密计算集群。

NodePoolInfo语法

"NodePoolInfo": {
  "ResourceGroupId": String,
  "Name": String
}

NodePoolInfo属性

属性名称

类型

必须

允许更新

描述

约束

Name

String

是

否

节点池名称。

无

ResourceGroupId

String

否

否

节点池所属的资源组ID。

无

KubernetesConfig语法

"KubernetesConfig": {
  "CpuPolicy": String,
  "Runtime": String,
  "CmsEnabled": Boolean,
  "UserData": String,
  "NodeNameMode": String,
  "RuntimeVersion": String,
  "Labels": List,
  "Unschedulable": Boolean,
  "Taints": List
}

KubernetesConfig属性

属性名称

类型

必须

允许更新

描述

约束

Runtime

String

是

是

容器运行时的名称。

无

RuntimeVersion

String

是

是

容器运行时版本。

无

CmsEnabled

Boolean

否

是

是否在ECS节点上安装云监控。

安装云监控后,可以在云监控控制台查看所创建ECS实例的监控信息。推荐开启。

取值:

  • true:在ECS节点上安装云监控。

  • false(默认值):不在ECS节点上安装云监控。

CpuPolicy

String

否

是

节点CPU管理策略。

当集群版本在1.12.6及以上时,支持以下两种策略:

  • static:此策略允许向节点上具有特定资源特征的POD授予增强的CPU亲和力和独占性。

  • none(默认值):表示启用现有的默认CPU亲和性方案。

Labels

List

否

是

节点标签,为Kubernetes集群节点添加标签。

更多信息,请参见Labels语法和Labels属性。

NodeNameMode

String

否

否

自定义节点名。

节点名称由三部分组成:前缀+节点IP地址子串+后缀。

  • 前缀和后缀均可由半角句号(.)分隔的一个或多个部分组成,每个部分可以使用小写英文字母、数字和短划线(-),节点名称首尾必须为小写英文字母和数字。

  • IP地址段长度指截取节点IP地址末尾的位数,取值范围为5~12。

Taints

List

否

否

污点配置。

更多信息,请参见Taints语法和Taints属性。

Unschedulable

Boolean

否

是

是否调度新添加的节点。

取值:

  • true:调度新节点。若想打开调度选项,可以在节点列表中开启。

  • false(默认值):节点扩容后设置为不可调度。

UserData

String

否

是

节点自定义数据。

无

Labels语法

"Labels": [
  {
    "Value": String,
    "Key": String
  }
]

Labels属性

属性名称

类型

必须

允许更新

描述

约束

Key

String

是

是

标签键。

无

Value

String

是

是

标签值。

无

Taints语法

"Taints": [
  {
    "Value": String,
    "Effect": String,
    "Key": String
  }
]

Taints属性

属性名称

类型

必须

允许更新

描述

约束

Key

String

是

否

污点名称。

无

Value

String

是

否

污点值。

无

Effect

String

否

否

调度策略。

取值:

  • NoSchedule(默认值):不能容忍,但仅影响调度过程,已被调度的Pod不受影响,仅对新增加的Pod生效。

  • NoExecute:不能容忍,当污点变动时,Pod对象会被驱逐。

  • PreferNoSchedule:柔性约束,节点现存Pod不受影响。

Management语法

"Management": {
  "UpgradeConfig": Map,
  "AutoRepair": Boolean,
  "Enable": Boolean
}

Management属性

属性名称

类型

必须

允许更新

描述

约束

Enable

Boolean

是

否

是否启用托管节点池。

取值:

  • true:启用托管节点池。

  • false(默认值):禁用托管节点池。

AutoRepair

Boolean

否

否

是否启用自动修复。

此参数仅在Enable取值为true时生效。

取值:

  • true:启用自动修复。

  • false(默认值):禁用自动修复。

UpgradeConfig

Map

否

否

自动升级的配置。

该属性仅在Enable取值为true时生效。

更多信息,请参见UpgradeConfig语法和UpgradeConfig属性。

UpgradeConfig语法

"UpgradeConfig": {
  "AutoUpgrade": Boolean,
  "SurgePercentage": Integer,
  "Surge": Integer,
  "MaxUnavailable": Integer
}

UpgradeConfig属性

属性名称

类型

必须

允许更新

描述

约束

AutoUpgrade

Boolean

否

否

是否启用自动升级。

取值:

  • true:启用自动升级。

  • false(默认值):禁用自动升级。

MaxUnavailable

Integer

否

否

最大不可用节点数量。

取值范围:1~1000。默认值:1。

Surge

Integer

否

否

额外节点数量。

SurgePercentage和Surge只能指定其中一个。

SurgePercentage

Integer

否

否

额外节点比例。

SurgePercentage和Surge只能指定其中一个。

AutoScaling语法

"AutoScaling": {
  "EipBandwidth": Integer,
  "Type": String,
  "IsBondEip": Boolean,
  "MinInstances": Integer,
  "Enable": Boolean,
  "MaxInstances": Integer,
  "EipInternetChargeType": String
}

AutoScaling属性

属性名称

类型

必须

允许更新

描述

约束

Enable

Boolean

是

否

是否启用自动伸缩。

取值:

  • true:开启节点池自动伸缩功能。

  • false(默认值):不开启自动伸缩。当取值为false时,其他AutoScaling配置参数将不生效。

EipBandwidth

Integer

否

否

EIP带宽峰值。

无

EipInternetChargeType

String

否

否

EIP计费类型。

取值:

  • PayByBandwidth(默认值):按固定带宽计费。

  • PayByTraffic:按使用流量计费。

IsBondEip

Boolean

否

否

是否绑定EIP。

取值:

  • true:绑定EIP。

  • false(默认值):不绑定EIP。

MaxInstances

Integer

否

否

自动伸缩组最大实例数。

无

MinInstances

Integer

否

否

自动伸缩组最小实例数。

无

Type

String

否

否

自动伸缩类型。

取值(按照自动伸缩实例类型):

  • cpu(默认值):普通实例型。

  • gpu:GPU实例型。

  • gpushare:GPU共享型。

  • spot:抢占式实例型。

ScalingGroup语法

"ScalingGroup": {
  "SpotInstanceRemedy": Boolean,
  "Platform": String,
  "DataDisks": List,
  "SystemDiskSize": Integer,
  "CompensateWithOnDemand": Boolean,
  "InstanceChargeType": String,
  "OnDemandPercentageAboveBaseCapacity": Integer,
  "AutoRenew": Boolean,
  "OnDemandBaseCapacity": Integer,
  "SystemDiskPerformanceLevel": String,
  "ImageId": String,
  "SpotPriceLimit": List,
  "InstanceTypes": List,
  "Tags": List,
  "SpotStrategy": String,
  "LoginPassword": String,
  "MultiAzPolicy": String,
  "AutoRenewPeriod": Integer,
  "ScalingPolicy": String,
  "SystemDiskEncrypted": Boolean,
  "KeyPair": String,
  "VSwitchIds": List,
  "SecurityGroupId": String,
  "SpotInstancePools": Integer,
  "Period": Integer,
  "InternetChargeType": String,
  "SystemDiskCategory": String,
  "InternetMaxBandwidthOut": Integer,
  "RdsInstances": List,
  "PeriodUnit": String,
  "ZoneIds": List,
  "SocEnabled": Boolean,
  "ImageType": String,
  "InstancePatterns": List,
  "SecurityHardeningOs": Boolean
}

ScalingGroup属性

属性名称

类型

必须

允许更新

描述

约束

SystemDiskSize

Integer

是

是

节点的系统磁盘大小。

单位:GiB。取值范围:40~500。

VSwitchIds

List

是

是

交换机ID。

无

AutoRenew

Boolean

否

是

节点池节点是否开启自动续费。

当InstanceChargeType取值为PrePaid时生效。

取值:

  • true(默认):自动续费。

  • false:不自动续费。

AutoRenewPeriod

Integer

否

是

节点池节点自动续费周期。

当InstanceChargeType取值为PrePaid,且AutoRenew取值为true时,AutoRenewPeriod生效且为必选值。

当PeriodUnit取值为Month时,取值:

  • 1(默认值)

  • 2

  • 3

  • 6

  • 12

CompensateWithOnDemand

Boolean

否

是

当MultiAzPolicy取值为COST_OPTIMIZED时,如果因价格、库存等原因无法创建足够的抢占式实例,是否允许自动尝试创建按量实例满足ECS实例数量要求。

取值:

  • true(默认值):允许自动尝试创建按量实例满足ECS实例数量要求。

  • false:不允许自动尝试创建按量实例满足ECS实例数量要求。

DataDisks

List

否

是

节点池节点数据盘配置。

更多信息,请参见DataDisks语法和DataDisks属性。

ImageId

String

否

是

自定义镜像ID。

默认使用系统提供的镜像。

ImageType

String

否

否

操作系统镜像的类型。

您必须指定此参数或Platform参数。

InstanceChargeType

String

否

是

节点池节点付费类型。

取值:

  • PrePaid:预付费。

  • PostPaid(默认值):按量付费。

InstancePatterns

List

否

是

实例属性配置。

更多信息,请参考InstancePatterns属性。

InstanceTypes

List

否

是

抢占式实例规格。

无

InternetChargeType

String

否

是

公网计费类型。

取值:

  • PayByBandwidth(默认值):按固定带宽计费。

  • PayByTraffic:按使用流量计费。

InternetMaxBandwidthOut

Integer

否

是

公网出带宽最大值。

单位:Mbit/s。

取值范围:1 Mbit/s~100 Mbit/s。

KeyPair

String

否

是

免密登录密钥对名称。

KeyPair和LoginPassword仅能指定其中一个。

说明

如果创建托管节点池,则只支持KeyPair。

LoginPassword

String

否

是

SSH登录密码。

KeyPair和LoginPassword仅能指定其中一个。

密码规则为8~30个字符,且至少包含英文字母、数字和特殊符号( ) ` ~ ! @ # $ % ^ & * - _ + = | { } [ ] : ; ' < > , . ? /中的三项。

MultiAzPolicy

String

否

是

多可用区伸缩组ECS实例扩容和缩容策略。

取值:

  • PRIORITY(默认值):根据您定义的交换机进行扩容或者缩容。当优先级较高的交换机所在可用区无法创建ECS实例时,自动使用下一优先级的交换机创建ECS实例。

  • COST_OPTIMIZED:按vCPU单价从低到高进行尝试创建。当伸缩配置设置了抢占式计费方式的多实例规格时,优先创建抢占式实例。您可以继续通过CompensateWithOnDemand指定当抢占式实例由于库存等原因无法创建时,是否自动尝试以按量付费的方式创建。

    说明

    COST_OPTIMIZED仅在伸缩配置设置了多实例规格或者选用了抢占式实例的情况下生效。

  • BALANCE:在伸缩组指定的多可用区之间均匀分配ECS实例。如果由于库存不足等原因使可用区之间变得不平衡,您可以通过APIRebalanceInstances重新平衡多可用区伸缩组内ECS实例的分布。

OnDemandBaseCapacity

Integer

否

是

伸缩组所需要按量实例个数的最小值。

取值范围:0~1000。当按量实例个数少于该值时,将优先创建按量实例。

OnDemandPercentageAboveBaseCapacity

Integer

否

是

伸缩组满足OnDemandBaseCapacity要求后,超出的实例中按量实例应占的比例。

取值范围:0~100。

Period

Integer

否

是

节点池节点自动续费周期,当选择预付费和自动续费时才生效,且为必选值。

当PeriodUnit取值为Month时,取值:

  • 1(默认值)

  • 2

  • 3

  • 6

  • 12

PeriodUnit

String

否

是

节点池节点付费周期。

当InstanceChargeType取值为PrePaid的时候需要指定周期。

取值:

  • Month:月。

  • Year:年。

Platform

String

否

是

操作系统。

取值:

  • CentOS

  • AliyunLinux(默认值)

  • Windows

  • WindowsCore

RdsInstances

List

否

是

RDS实例ID。

无

ScalingPolicy

String

否

是

伸缩组模式。

取值:

  • release(默认值):标准模式,根据申请资源值的使用量,通过创建、释放ECS的方式进行伸缩。

  • recycle:极速模式,通过创建、停机、启动的方式进行伸缩,提高再次伸缩的速度(停机时计算资源不收费,只收取存储费用,本地盘机型除外)。

SecurityGroupId

String

否

是

安全组ID。

无

SecurityHardeningOs

Boolean

否

否

阿里云 OS 安全加固。

取值:

  • true:开启阿里云 OS 安全加固。

  • false:不开启阿里云 OS 安全加固。

默认值:false。

SocEnabled

Boolean

否

否

指定是否启用 MLPS 安全加固。

无

SpotInstancePools

Integer

否

是

指定可用实例规格的个数,伸缩组将按成本最低的多个规格均衡创建抢占式实例。

取值范围:1~10。

SpotInstanceRemedy

Boolean

否

是

是否使用抢占式实例。

取值:

  • true(默认值):使用抢占式实例。当收到抢占式实例将被回收的系统消息时,伸缩组将尝试创建新的实例,替换掉将被回收的抢占式实例。

  • false:不使用抢占式实例。

更多信息,请参见创建抢占式实例。

SpotPriceLimit

List

否

是

设置实例的每小时最高价格。

最大支持3位小数,SpotStrategy取值为SpotWithPriceLimit时生效。

更多信息,请参见SpotPriceLimit语法和SpotPriceLimit属性。

SpotStrategy

String

否

是

抢占式实例类型。

取值:

  • NoSpot:非抢占式实例。

  • SpotWithPriceLimit:设置抢占实例价格上限。

  • SpotAsPriceGo:系统自动出价,跟随当前市场实际价格。

更多信息,请参见使用抢占式实例。

SystemDiskCategory

String

否

是

节点系统盘类型。

取值:

  • cloud_efficiency(默认值):高效云盘。

  • cloud_ssd:SSD云盘。

  • cloud_essd:ESSD云盘。

SystemDiskEncrypted

Boolean

否

是

是否加密系统盘。

无

  • true

  • false

默认值: false.

SystemDiskPerformanceLevel

String

否

是

设置云盘的性能等级。

取值:

  • PL1:单盘最高随机读写IOPS 5万。

  • PL2:单盘最高随机读写IOPS 10万。

  • PL3:单盘最高随机读写IOPS 100万。

更多信息,请参见ESSD云盘。

Tags

List

否

是

仅为ECS实例添加标签。

标签键不可以重复,最大长度为128个字符;标签键和标签值都不能以aliyun、acs:开头,或包含https://、http://。

更多信息,请参见Tags语法和Tags属性。

ZoneIds

List

否

是

可用区ID列表。

无

InstancePatterns语法

"InstancePatterns": [
  {
    "CpuArchitectures": List,
    "MaxCpuCores": Integer,
    "MinMemorySize": Integer,
    "Memory": Integer,
    "InstanceFamilyLevel": String,
    "MinCpuCores": Integer,
    "Cores": Integer,
    "InstanceTypeFamilies": List,
    "InstanceCategories": List,
    "ExcludedInstanceTypes": List,
    "MaxMemorySize": Integer
  }
]

InstancePatterns属性

属性名称

类型

必须

允许更新

描述

约束

Cores

Integer

否

否

实例规格的 vCPU 内核数目。

无

CpuArchitectures

List

否

否

实例的 CPU 架构。

取值:

  • X86

  • ARM

ExcludedInstanceTypes

List

否

否

需要排除的实例规格。

无

InstanceCategories

List

否

否

实例分类。

无

InstanceFamilyLevel

String

否

否

实例规格族级别。

无

InstanceTypeFamilies

List

否

否

指定实例规格族。

无

MaxCpuCores

Integer

否

否

实例规格的最大 vCPU 内核数目

无

MaxMemorySize

Integer

否

否

实例规格的最大内存。

单位:GiB。

Memory

Integer

否

否

实例规格的内存大小。

单位为 GiB。

MinCpuCores

Integer

否

否

实例规格的最小 vCPU 内核数目。

无

MinMemorySize

Integer

否

否

实例规格的最小内存。

单位:GiB。

DataDisks语法

"DataDisks": [
  {
    "Category": String,
    "Encrypted": Boolean,
    "PerformanceLevel": String,
    "Size": Integer,
    "AutoSnapshotPolicyId": String,
    "Categories": List
  }
]

DataDisks属性

属性名称

类型

必须

允许更新

描述

约束

AutoSnapshotPolicyId

String

否

是

选择自动快照策略ID,云盘会按照快照策略自动备份。

默认值为空,表示不自动备份。

Categories

List

否

否

数据磁盘类型的列表。

无

Category

String

否

是

数据盘类型。

取值:

  • cloud_efficiency(默认值):高效云盘。

  • cloud_ssd:SSD云盘。

  • cloud_essd:ESSD云盘。

Encrypted

Boolean

否

是

是否对数据盘加密。

取值:

  • true:对数据盘加密。

  • false(默认值):不对数据盘加密。

PerformanceLevel

String

否

是

设置云盘的性能等级。

取值:

  • PL1:单盘最高随机读写IOPS 5万。

  • PL2:单盘最高随机读写IOPS 10万。

  • PL3:单盘最高随机读写IOPS 100万。

更多信息,请参见ESSD云盘。

Size

Integer

否

是

数据盘大小。

取值范围:40~32768。

默认值:120。

单位:GiB。

SpotPriceLimit语法

"SpotPriceLimit": [
  {
    "PriceLimit": Number,
    "InstanceType": String
  }
]

SpotPriceLimit属性

属性名称

类型

必须

允许更新

描述

约束

InstanceType

String

是

是

可抢占实例的实例类型。

无

PriceLimit

Number

是

是

可抢占实例的价格限制。

无

Tags语法

"Tags": [
  {
    "Value": String,
    "Key": String
  }
]

Tags属性

属性名称

类型

必须

允许更新

描述

约束

Key

String

是

是

标签键。

无

Value

String

是

是

标签值。

无

返回值

Fn::GetAtt

  • NodePoolId:集群节点池ID。

示例

场景 1 :创建节点池(固定入参)。

快速创建

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  TeeConfig:
    Type: Json
    Description: The configurations of confidential computing.
    Default: |-
      {
        "TeeEnable": true
      }
  ClusterId:
    Type: String
    Description: Cluster ID.
    AssociationProperty: ALIYUN::CS::Cluster::ClusterId
  NodePoolInfo:
    Type: Json
    Description: The configurations of the node pool.
    Default: |-
      {
        "Name": "test"
      }
  KubernetesConfig:
    Type: Json
    Description: The configurations of the ACK cluster.
    Default: |-
      {
        "CpuPolicy": "static",
        "Runtime": "containerd",
        "CmsEnabled": true,
        "UserData": "echo 'hello'",
        "NodeNameMode": "customized,aliyun.com,5,test",
        "RuntimeVersion": "1.4.8",
        "Unschedulable": false
      }
  Count:
    Type: Number
    Description: The number of nodes in the node pool.
    Default: 1
  Management:
    Type: Json
    Description: The configurations of the managed node pool.
    Default: |-
      {
        "UpgradeConfig": {
          "AutoUpgrade": true,
          "Surge": 1,
          "MaxUnavailable": 1
        },
        "AutoRepair": true,
        "Enable": true
      }
  ScalingGroup:
    Type: Json
    Description: The configurations of the scaling group used by the node pool.
    Default: |-
      {
        "SpotInstanceRemedy": true,
        "Platform": "AliyunLinux",
        "SystemDiskSize": 120,
        "InstanceChargeType": "PostPaid",
        "SystemDiskPerformanceLevel": "PL1",
        "ImageId": "aliyun_2_1903_x64_20G_alibase_20210726.vhd",
        "InstanceTypes": [
          "ecs.ebmhfc6.20xlarge"
        ],
        "LoginPassword": "test****",
        "MultiAzPolicy": "BALANCE",
        "VSwitchIds": [
          "vsw-*****"
        ],
        "SystemDiskCategory": "cloud_essd",
        "InternetMaxBandwidthOut": 0
      }
Resources:
  ClusterNodePool:
    Type: ALIYUN::CS::ClusterNodePool
    Properties:
      TeeConfig:
        Ref: TeeConfig
      ClusterId:
        Ref: ClusterId
      NodePoolInfo:
        Ref: NodePoolInfo
      KubernetesConfig:
        Ref: KubernetesConfig
      Count:
        Ref: Count
      Management:
        Ref: Management
      ScalingGroup:
        Ref: ScalingGroup
Outputs:
  NodePoolId:
    Description: Cluster node pool ID.
    Value:
      Fn::GetAtt:
        - ClusterNodePool
        - NodePoolId
                    
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "TeeConfig": {
      "Type": "Json",
      "Description": "The configurations of confidential computing.",
      "Default": "{\n  \"TeeEnable\": true\n}"
    },
    "ClusterId": {
      "Type": "String",
      "Description": "Cluster ID.",
      "AssociationProperty": "ALIYUN::CS::Cluster::ClusterId"
    },
    "NodePoolInfo": {
      "Type": "Json",
      "Description": "The configurations of the node pool.",
      "Default": "{\n  \"Name\": \"test\"\n}"
    },
    "KubernetesConfig": {
      "Type": "Json",
      "Description": "The configurations of the ACK cluster.",
      "Default": "{\n  \"CpuPolicy\": \"static\",\n  \"Runtime\": \"containerd\",\n  \"CmsEnabled\": true,\n  \"UserData\": \"echo 'hello'\",\n  \"NodeNameMode\": \"customized,aliyun.com,5,test\",\n  \"RuntimeVersion\": \"1.4.8\",\n  \"Unschedulable\": false\n}"
    },
    "Count": {
      "Type": "Number",
      "Description": "The number of nodes in the node pool.",
      "Default": 1
    },
    "Management": {
      "Type": "Json",
      "Description": "The configurations of the managed node pool.",
      "Default": "{\n  \"UpgradeConfig\": {\n    \"AutoUpgrade\": true,\n    \"Surge\": 1,\n    \"MaxUnavailable\": 1\n  },\n  \"AutoRepair\": true,\n  \"Enable\": true\n}"
    },
    "ScalingGroup": {
      "Type": "Json",
      "Description": "The configurations of the scaling group used by the node pool.",
      "Default": "{\n  \"SpotInstanceRemedy\": true,\n  \"Platform\": \"AliyunLinux\",\n  \"SystemDiskSize\": 120,\n  \"InstanceChargeType\": \"PostPaid\",\n  \"SystemDiskPerformanceLevel\": \"PL1\",\n  \"ImageId\": \"aliyun_2_1903_x64_20G_alibase_20210726.vhd\",\n  \"InstanceTypes\": [\n    \"ecs.ebmhfc6.20xlarge\"\n  ],\n  \"LoginPassword\": \"test****\",\n  \"MultiAzPolicy\": \"BALANCE\",\n  \"VSwitchIds\": [\n    \"vsw-*****\"\n  ],\n  \"SystemDiskCategory\": \"cloud_essd\",\n  \"InternetMaxBandwidthOut\": 0\n}"
    }
  },
  "Resources": {
    "ClusterNodePool": {
      "Type": "ALIYUN::CS::ClusterNodePool",
      "Properties": {
        "TeeConfig": {
          "Ref": "TeeConfig"
        },
        "ClusterId": {
          "Ref": "ClusterId"
        },
        "NodePoolInfo": {
          "Ref": "NodePoolInfo"
        },
        "KubernetesConfig": {
          "Ref": "KubernetesConfig"
        },
        "Count": {
          "Ref": "Count"
        },
        "Management": {
          "Ref": "Management"
        },
        "ScalingGroup": {
          "Ref": "ScalingGroup"
        }
      }
    }
  },
  "Outputs": {
    "NodePoolId": {
      "Description": "Cluster node pool ID.",
      "Value": {
        "Fn::GetAtt": [
          "ClusterNodePool",
          "NodePoolId"
        ]
      }
    }
  }
}

场景 2 :创建节点池(动态入参)。

快速创建

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  ClusterId:
    AssociationProperty: ALIYUN::CS::Cluster::ClusterId
    Type: String
  VpcId:
    Type: String
    AssociationProperty: ALIYUN::ECS::VPC::VPCId
  ZoneId1:
    Type: String
    AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
    AssociationPropertyMetadata:
      ExclusiveTo:
        - ZoneId2
    Label:
      en: Availability Zone
      zh-cn: 可用区1
  VSwitchId1:
    Type: String
    AssociationProperty: ALIYUN::ECS::VSwitch::VSwitchId
    AssociationPropertyMetadata:
      ZoneId: ${ZoneId1}
      VpcId: ${VpcId}
  ZoneId2:
    Type: String
    AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
    AssociationPropertyMetadata:
      ExclusiveTo:
        - ZoneId1
    Label:
      en: Availability Zone
      zh-cn: 可用区2
  VSwitchId2:
    Type: String
    AssociationProperty: ALIYUN::ECS::VSwitch::VSwitchId
    AssociationPropertyMetadata:
      ZoneId: ${ZoneId2}
      VpcId: ${VpcId}
  InstanceType:
    Type: CommaDelimitedList
    AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
    AssociationPropertyMetadata:
      InstanceChargeType: PostPaid
      SystemDiskCategory: cloud_essd
      CreateACKClusterParams:
        NetworkPlugin: terway-eniip
    Label:
      en: Instance Type
      zh-cn: 实例规格
  InstancePassword:
    NoEcho: true
    Type: String
    Description:
      en: >-
        Server login password, Length 8-30, must contain three(Capital letters,
        lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special
        symbol in)
      zh-cn: >-
        服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
        中的特殊符号)
    Label:
      en: Instance Password
      zh-cn: 实例密码
    ConstraintDescription:
      en: >-
        Length 8-30, must contain three(Capital letters, lowercase letters,
        numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)
      zh-cn: '长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;''<>,.?/ 中的特殊符号)'
    AssociationProperty: 'ALIYUN::ECS::Instance::Password'
    Default: null
Resources:
  NodePools:
    Type: 'ALIYUN::CS::ClusterNodePool'
    Properties:
      ClusterId:
        Ref: ClusterId
      NodePoolInfo:
          Name: k8s-hpa-cluster-nodepool
      ScalingGroup:
        VSwitchIds:
          - Ref: VSwitchId1
          - Ref: VSwitchId2
        ZoneIds:
          - Ref: ZoneId1
          - Ref: ZoneId2
        SystemDiskCategory: cloud_essd
        SystemDiskPerformanceLevel: PL0
        SystemDiskSize: 40
        InstanceTypes:
          Ref: InstanceType
        LoginPassword:
          Ref: InstancePassword
        Platform: AliyunLinux
        ImageId: aliyun_3_9_x64_20G_alibase_20231219.vhd
      KubernetesConfig:
        Runtime: containerd
        RuntimeVersion: 1.6.28
      AutoScaling:
        Enable: true
        MinInstances: 2
        MaxInstances: 10
Outputs:
  NodePoolId:
    Description:
      zh-cn: coffee服务访问地址。
      en: The addresses of coffee service.
    Value:
      Ref: NodePools
Metadata:
  'ALIYUN::ROS::Interface':
    ParameterGroups:
      - Parameters:
          - ClusterId
          - VpcId
          - ZoneId1
          - VSwitchId1
          - ZoneId2
          - VSwitchId2
          - InstanceType
          - InstancePassword

{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "ClusterId": {
      "AssociationProperty": "ALIYUN::CS::Cluster::ClusterId",
      "Type": "String"
    },
    "VpcId": {
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::VPC::VPCId"
    },
    "ZoneId1": {
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",
      "AssociationPropertyMetadata": {
        "ExclusiveTo": [
          "ZoneId2"
        ]
      },
      "Label": {
        "en": "Availability Zone",
        "zh-cn": "可用区1"
      }
    },
    "VSwitchId1": {
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::VSwitch::VSwitchId",
      "AssociationPropertyMetadata": {
        "ZoneId": "${ZoneId1}",
        "VpcId": "${VpcId}"
      }
    },
    "ZoneId2": {
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",
      "AssociationPropertyMetadata": {
        "ExclusiveTo": [
          "ZoneId1"
        ]
      },
      "Label": {
        "en": "Availability Zone",
        "zh-cn": "可用区2"
      }
    },
    "VSwitchId2": {
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::VSwitch::VSwitchId",
      "AssociationPropertyMetadata": {
        "ZoneId": "${ZoneId2}",
        "VpcId": "${VpcId}"
      }
    },
    "InstanceType": {
      "Type": "CommaDelimitedList",
      "AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",
      "AssociationPropertyMetadata": {
        "InstanceChargeType": "PostPaid",
        "SystemDiskCategory": "cloud_essd",
        "CreateACKClusterParams": {
          "NetworkPlugin": "terway-eniip"
        }
      },
      "Label": {
        "en": "Instance Type",
        "zh-cn": "实例规格"
      }
    },
    "InstancePassword": {
      "NoEcho": true,
      "Type": "String",
      "Description": {
        "en": "Server login password, Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)",
        "zh-cn": "服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)"
      },
      "Label": {
        "en": "Instance Password",
        "zh-cn": "实例密码"
      },
      "ConstraintDescription": {
        "en": "Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)",
        "zh-cn": "长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)"
      },
      "AssociationProperty": "ALIYUN::ECS::Instance::Password",
      "Default": null
    }
  },
  "Resources": {
    "NodePools": {
      "Type": "ALIYUN::CS::ClusterNodePool",
      "Properties": {
        "ClusterId": {
          "Ref": "ClusterId"
        },
        "NodePoolInfo": {
          "Name": "k8s-hpa-cluster-nodepool"
        },
        "ScalingGroup": {
          "VSwitchIds": [
            {
              "Ref": "VSwitchId1"
            },
            {
              "Ref": "VSwitchId2"
            }
          ],
          "ZoneIds": [
            {
              "Ref": "ZoneId1"
            },
            {
              "Ref": "ZoneId2"
            }
          ],
          "SystemDiskCategory": "cloud_essd",
          "SystemDiskPerformanceLevel": "PL0",
          "SystemDiskSize": 40,
          "InstanceTypes": {
            "Ref": "InstanceType"
          },
          "LoginPassword": {
            "Ref": "InstancePassword"
          },
          "Platform": "AliyunLinux",
          "ImageId": "aliyun_3_9_x64_20G_alibase_20231219.vhd"
        },
        "KubernetesConfig": {
          "Runtime": "containerd",
          "RuntimeVersion": "1.6.28"
        },
        "AutoScaling": {
          "Enable": true,
          "MinInstances": 2,
          "MaxInstances": 10
        }
      }
    }
  },
  "Outputs": {
    "NodePoolId": {
      "Description": {
        "zh-cn": "coffee服务访问地址。",
        "en": "The addresses of coffee service."
      },
      "Value": {
        "Ref": "NodePools"
      }
    }
  },
  "Metadata": {
    "ALIYUN::ROS::Interface": {
      "ParameterGroups": [
        {
          "Parameters": [
            "ClusterId",
            "VpcId",
            "ZoneId1",
            "VSwitchId1",
            "ZoneId2",
            "VSwitchId2",
            "InstanceType",
            "InstancePassword"
          ]
        }
      ]
    }
  }
}

场景 3 :创建托管Kubernetes集群,配置VPC、节点池。

快速创建

ROSTemplateFormatVersion: '2015-09-01'
Description:
  zh-cn: 创建托管Kubernetes集群,配置VPC、节点池、HPA及日志服务,实现容器应用的自动伸缩与监控。
  en: Create a managed Kubernetes cluster, configure Virtual Private Cloud (VPC),
    node pools, Horizontal Pod Autoscaler (HPA), and logging services to enable automatic
    scaling and monitoring of containerized applications.
Parameters:
  CommonName:
    Type: String
    Default:  k8s-hpa-cluster
  SlsProjectName:
    Type: String
    Label:
      en: Name of sls project
      zh-cn: 日志项目的名称
    Description:
      en: The name contains 3 to 36 characters. It must start and end with a lowercase letter or number. The value can contain lowercase letters, digits, and hyphens (-).
      zh-cn: 长度为3~36个字符。必须以小写英文字母或数字开头和结尾。可包含小写英文字母、数字和短划线(-)。
    AssociationProperty: AutoCompleteInput
    AssociationPropertyMetadata:
      Length: 5
      Prefix: k8s-hpa-sls-project-
      CharacterClasses:
        - Class: lowercase
          min: 1
  ManagedKubernetesClusterName:
    Type: String
    Label:
      en: Managed Kubernetes Cluster Name
      zh-cn: ACK托管版集群名称
    AssociationProperty: AutoCompleteInput
    AssociationPropertyMetadata:
      Length: 5
      Prefix: k8s-hpa-cluster-
      CharacterClasses:
        - Class: lowercase
          min: 1
  ZoneId1:
    Type: String
    AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
    AssociationPropertyMetadata:
      ExclusiveTo:
        - ZoneId2
    Label:
      en: Availability Zone
      zh-cn: 可用区1
  ZoneId2:
    Type: String
    AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
    AssociationPropertyMetadata:
      ExclusiveTo:
        - ZoneId1
    Label:
      en: Availability Zone
      zh-cn: 可用区2
  InstanceType:
    Type: CommaDelimitedList
    AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
    AssociationPropertyMetadata:
      InstanceChargeType: PostPaid
      SystemDiskCategory: cloud_essd
      CreateACKClusterParams:
        NetworkPlugin: terway-eniip
    Label:
      en: Instance Type
      zh-cn: 实例规格
  InstancePassword:
    NoEcho: true
    Type: String
    Description:
      en: >-
        Server login password, Length 8-30, must contain three(Capital letters,
        lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special
        symbol in)
      zh-cn: >-
        服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
        中的特殊符号)
    Label:
      en: Instance Password
      zh-cn: 实例密码
    ConstraintDescription:
      en: >-
        Length 8-30, must contain three(Capital letters, lowercase letters,
        numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)
      zh-cn: '长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;''<>,.?/ 中的特殊符号)'
    AssociationProperty: 'ALIYUN::ECS::Instance::Password'
    Default: null
Resources:
  Vpc:
    Type: 'ALIYUN::ECS::VPC'
    Properties:
      CidrBlock: 10.0.0.0/8
      VpcName:
        Fn::Sub: ${CommonName}-vpc
  VSwitch1:
    Type: 'ALIYUN::ECS::VSwitch'
    Properties:
      VpcId:
        Ref: Vpc
      CidrBlock: 10.0.0.0/24
      ZoneId:
        Ref: ZoneId1
      VSwitchName:
        Fn::Sub: ${CommonName}-vsw
  VSwitch2:
    Type: 'ALIYUN::ECS::VSwitch'
    Properties:
      VpcId:
        Ref: Vpc
      CidrBlock: 10.0.1.0/24
      ZoneId:
        Ref: ZoneId2
      VSwitchName:
        Fn::Sub: ${CommonName}-vsw
  SecurityGroup:
    Type: 'ALIYUN::ECS::SecurityGroup'
    Properties:
      VpcId:
        Ref: Vpc
      SecurityGroupName:
        Fn::Sub: ${CommonName}-sg
      SecurityGroupIngress:
        - PortRange: 443/443
          SourceCidrIp: 0.0.0.0/0
          IpProtocol: tcp
        - PortRange: 80/80
          SourceCidrIp: 0.0.0.0/0
          IpProtocol: tcp
  SlsProject:
    Type: 'ALIYUN::SLS::Project'
    Properties:
      Name:
        Ref: SlsProjectName
  AliyunCSManagedAutoScalerRole:
    Type: 'ALIYUN::RAM::Role'
    Properties:
      RoleName: AliyunCSManagedAutoScalerRole
      Description: CS使用此角色来访问您在其他云产品中的资源。
      AssumeRolePolicyDocument:
        Version: '1'
        Statement:
          - Action: sts:AssumeRole
            Effect: Allow
            Principal:
              Service:
                - cs.aliyuncs.com
      MaxSessionDuration: 3600
      IgnoreExisting: true
      DeletionForce: true
      PolicyAttachments:
        System:
          - AliyunCSManagedAutoScalerRolePolicy
  AckCluster:
    Type: 'ALIYUN::CS::ManagedKubernetesCluster'
    DependsOn: AliyunCSManagedAutoScalerRole
    Properties:
      VpcId:
        Ref: Vpc
      VSwitchIds:
        - Ref: VSwitch1
        - Ref: VSwitch2
      PodVswitchIds:
        - Ref: VSwitch1
        - Ref: VSwitch1
      Name:
        Ref: ManagedKubernetesClusterName
      KubernetesVersion: 1.31.1-aliyun.1
      ServiceCidr: 192.168.0.0/16
      ClusterSpec: ack.pro.small
      LoadBalancerSpec: slb.s2.small
      IsEnterpriseSecurityGroup: true
      SnatEntry: true
      NumOfNodes: 0
      EndpointPublicAccess: true
      Platform: AliyunLinux
      Addons:
        - Name: ack-node-local-dns
        - Name: terway-eniip
          Config: '{"IPVlan":"false","NetworkPolicy":"false","ENITrunking":"false"}'
        - Name: csi-plugin
        - Name: csi-provisioner
        - Name: storage-operator
          Config: '{"CnfsOssEnable":"false","CnfsNasEnable":"false"}'
        - Name: nginx-ingress-controller
          Disabled: true
        - Name: logtail-ds
          Config: '{"IngressDashboardEnabled":"true"}'
        - Name: alb-ingress-controller
          Version: ""
          Config:
            Fn::Sub: >-
              {"albIngress":{"AddressType":"Internet","ZoneMappings":{"${ZoneId1}":["${VSwitch1}"],
              "${ZoneId2}":["${VSwitch2}"]},"CreateDefaultALBConfig":true}}
        - Name: ack-helm-manager
        - Name: arms-prometheus
      ProxyMode: ipvs
      DeleteOptions:
        - ResourceType: ALB
          DeleteMode: delete
        - ResourceType: SLB
          DeleteMode: delete
        - ResourceType: SLS_Data
          DeleteMode: delete
        - ResourceType: SLS_ControlPlane
          DeleteMode: delete
        - ResourceType: PrivateZone
          DeleteMode: delete
  NodePools:
    Type: 'ALIYUN::CS::ClusterNodePool'
    Properties:
      ClusterId:
        Ref: AckCluster
      NodePoolInfo:
          Name: k8s-hpa-cluster-nodepool
      ScalingGroup:
        VSwitchIds:
          - Ref: VSwitch1
          - Ref: VSwitch2
        ZoneIds:
          - Ref: ZoneId1
          - Ref: ZoneId2
        SystemDiskCategory: cloud_essd
        SystemDiskPerformanceLevel: PL0
        SystemDiskSize: 40
        InstanceTypes:
          Ref: InstanceType
        LoginPassword:
          Ref: InstancePassword
        Platform: AliyunLinux
        ImageId: aliyun_3_9_x64_20G_alibase_20231219.vhd
      KubernetesConfig:
        Runtime: containerd
        RuntimeVersion: 1.6.28
      AutoScaling:
        Enable: true
        MinInstances: 2
        MaxInstances: 10
  Sleep:
    Type: 'ALIYUN::ROS::Sleep'
    DependsOn: NodePools
    Properties:
      CreateDuration: 300
  AckMetricsAdapter:
    Type: 'ALIYUN::CS::ClusterHelmApplication'
    DependsOn: Sleep
    Properties:
      Namespace: kube-system
      ChartUrl: 'https://aliacs-app-catalog.oss-cn-hangzhou.aliyuncs.com/charts-incubator/ack-alibaba-cloud-metrics-adapter-1.3.3.tgz'
      ClusterId:
        Ref: AckCluster
      Name: ack-alibaba-cloud-metrics-adapter
      ChartValues:
        AlibabaCloudMetricsAdapter:
          commonLabels: ''
          replicas: 1
          resources:
            metricsAdapterDeployment:
              resources:
                limits:
                  cpu: 0.5
                  memory: 1Gi
                requests:
                  cpu: 100m
                  memory: 200Mi
            configReloader:
              resources:
                limits:
                  cpu: 20m
                  memory: 30Mi
                requests:
                  cpu: 20m
                  memory: 30Mi
          listenPort: 443
          costWeights:
            cpu: '1.0'
            memory: '0.0'
          image:
            repository: registry-cn-hangzhou-vpc.ack.aliyuncs.com/acs/alibaba-cloud-metrics-adapter-amd64
            tag: v0.2.7-f1ee5c3-aliyun
            pullPolicy: Always
          nameOverride: ''
          fullnameOverride: ''
          service:
            type: ClusterIP
          serviceAccountName: ack-alibaba-cloud-metrics-adapter
          annotations: { }
          nodeSelector: { }
          tolerations: [ ]
          env:
            - AccessKeyId: ''
            - AccessKeySecret: ''
            - Region: ''
          affinity: { }
          prometheus:
            enabled: true
            url: { }
            metricsRelistInterval: 1m
            logLevel: 5
            adapter:
              rules:
                default: false
                custom:
                  - seriesQuery: container_memory_working_set_bytes{namespace!="",pod!=""}
                    resources:
                      overrides:
                        namespace:
                          resource: namespace
                        pod:
                          resource: pod
                    name:
                      matches: ^(.*)_bytes
                      as: ${1}_bytes_per_second
                    metricsQuery: sum(<<.Series>>{<<.LabelMatchers>>}) by (<<.GroupBy>>)
                  - seriesQuery: container_cpu_usage_seconds_total{namespace!="",pod!=""}
                    resources:
                      overrides:
                        namespace:
                          resource: namespace
                        pod:
                          resource: pod
                    name:
                      matches: ^(.*)_seconds_total
                      as: ${1}_core_per_second
                    metricsQuery: sum(rate(<<.Series>>{<<.LabelMatchers>>}[1m])) by (<<.GroupBy>>)
        ConfigReloader:
          image:
            repository: registry-vpc.cn-hangzhou.aliyuncs.com/acs/configmap-reload
            tag: v0.0.1
  InstallBackendApp:
    Type: 'ALIYUN::CS::ClusterApplication'
    DependsOn: AckMetricsAdapter
    Properties:
      ClusterId:
        Ref: AckCluster
      YamlContent:
        Fn::Sub: |-
          apiVersion: apps/v1
          kind: Deployment
          metadata:
            name: coffee
          spec:
            replicas: 2
            selector:
              matchLabels:
                app: coffee
            template:
              metadata:
                labels:
                  app: coffee
              spec:
                containers:
                - name: coffee
                  image: registry.${ALIYUN::Region}.aliyuncs.com/acs-sample/nginxdemos:latest
                  ports:
                  - containerPort: 80
                  resources:
                    limits:
                      cpu: 500m
                      memory: 1Gi
                    requests:
                      cpu: 500m
                      memory: 512Mi
          ---
          apiVersion: v1
          kind: Service
          metadata:
            name: coffee-svc
          spec:
            ports:
            - port: 80
              targetPort: 80
              protocol: TCP
            selector:
              app: coffee
            type: NodePort
          ---
          apiVersion: apps/v1
          kind: Deployment
          metadata:
            name: tea
          spec:
            replicas: 2
            selector:
              matchLabels:
                app: tea
            template:
              metadata:
                labels:
                  app: tea
              spec:
                containers:
                - name: tea
                  image: registry.${ALIYUN::Region}.aliyuncs.com/acs-sample/nginxdemos:latest
                  ports:
                  - containerPort: 80
                  resources:
                    limits:
                      cpu: 500m
                      memory: 1Gi
                    requests:
                      cpu: 500m
                      memory: 512Mi
          ---
          apiVersion: v1
          kind: Service
          metadata:
            name: tea-svc
          spec:
            ports:
            - port: 80
              targetPort: 80
              protocol: TCP
            selector:
              app: tea
            type: NodePort
  AlbConfig:
    Type: 'ALIYUN::CS::ClusterApplication'
    DependsOn: InstallBackendApp
    Properties:
      ClusterId:
        Ref: AckCluster
      YamlContent:
        Fn::Sub: |-
          apiVersion: alibabacloud.com/v1
          kind: AlbConfig
          metadata:
            name: k8s-hpa-alb-config
          spec:
            config:
              name: k8s-hpa-alb
              addressType: Internet
              zoneMappings:
              - vSwitchId: ${VSwitch1}
              - vSwitchId: ${VSwitch2}
              accessLogConfig:
                logProject: ${SlsProject}
                logStore: "alb_k8s_hpa_sls_logstore"
            listeners:
              - port: 80
                protocol: HTTP
  IngressClass:
    Type: 'ALIYUN::CS::ClusterApplication'
    DependsOn: AlbConfig
    Properties:
      ClusterId:
        Ref: AckCluster
      YamlContent:
        Fn::Sub: |-
          apiVersion: networking.k8s.io/v1
          kind: IngressClass
          metadata:
            name: k8s-hpa-alb-ingress-class
          spec:
            controller: ingress.k8s.alibabacloud/alb
            parameters:
              apiGroup: alibabacloud.com
              kind: AlbConfig
              name: k8s-hpa-alb-config
  Ingress:
    Type: 'ALIYUN::CS::ClusterApplication'
    DependsOn: IngressClass
    Properties:
      ClusterId:
        Ref: AckCluster
      YamlContent:
        Fn::Sub: |-
          apiVersion: networking.k8s.io/v1
          kind: Ingress
          metadata:
            name: k8s-hpa-alb-ingress
          spec:
            ingressClassName: k8s-hpa-alb-ingress-class
            rules:
             - http:
                paths:
                - path: /tea
                  pathType: ImplementationSpecific
                  backend:
                    service:
                      name: tea-svc
                      port:
                        number: 80
                - path: /coffee
                  pathType: ImplementationSpecific
                  backend:
                    service:
                      name: coffee-svc
                      port: 
                        number: 80
  Hpa:
    Type: 'ALIYUN::CS::ClusterApplication'
    DependsOn: WaitAlbIngress
    Properties:
      ClusterId:
        Ref: AckCluster
      YamlContent:
        Fn::Sub: |-
          apiVersion: autoscaling/v2
          kind: HorizontalPodAutoscaler
          metadata:
            name: k8s-alb-tea-hpa
          spec:
            scaleTargetRef:
              apiVersion: apps/v1
              kind: Deployment
              name: tea
            minReplicas: 2
            maxReplicas: 10
            metrics:
              - type: External
                external:
                  metric:
                    name: sls_alb_ingress_qps
                    selector:
                      matchLabels:
                        sls.project: ${SlsProject}
                        sls.logstore: "alb_k8s_hpa_sls_logstore" 
                        sls.ingress.route: "default-tea-svc-80"
                  target:
                    type: AverageValue
                    averageValue: 2
              - resource:
                  name: cpu
                  target:
                    averageUtilization: 80
                    type: Utilization
                type: Resource
              - resource:
                  name: memory
                  target:
                    averageUtilization: 80
                    type: Utilization
                type: Resource
  WaitAlbIngress:
    Type: 'ALIYUN::ROS::Sleep'
    DependsOn: Ingress
    Properties:
      CreateDuration: 120
  IngressInfo:
    Type: 'DATASOURCE::CS::ClusterApplicationResources'
    DependsOn: WaitAlbIngress
    Properties:
      ClusterId:
        Ref: AckCluster
      Kind: Ingress
      Namespace: default
      JsonPath: $.items.[0].status.loadBalancer.ingress.[0].hostname
      FirstMatch: true
Outputs:
  TeaUrl:
    Description:
      zh-cn: tea服务访问地址。
      en: The addresses of tea service.
    Value:
      'Fn::Sub': http://${IngressInfo}/tea
  CoffeeUrl:
    Description:
      zh-cn: coffee服务访问地址。
      en: The addresses of coffee service.
    Value:
      'Fn::Sub': http://${IngressInfo}/coffee
Metadata:
  'ALIYUN::ROS::Interface':
    ParameterGroups:
      - Parameters:
          - SlsProjectName
          - ManagedKubernetesClusterName
          - ZoneId1
          - ZoneId2
          - InstanceType
          - InstancePassword
    TemplateTags:
      - acs:technical-solution:micro:通过HPA实现容器应用的水平弹性伸缩-tech_solu_125
    Hidden:
      - CommonName
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": {
    "zh-cn": "创建托管Kubernetes集群,配置VPC、节点池、HPA及日志服务,实现容器应用的自动伸缩与监控。",
    "en": "Create a managed Kubernetes cluster, configure Virtual Private Cloud (VPC), node pools, Horizontal Pod Autoscaler (HPA), and logging services to enable automatic scaling and monitoring of containerized applications."
  },
  "Parameters": {
    "CommonName": {
      "Type": "String",
      "Default": "k8s-hpa-cluster"
    },
    "SlsProjectName": {
      "Type": "String",
      "Label": {
        "en": "Name of sls project",
        "zh-cn": "日志项目的名称"
      },
      "Description": {
        "en": "The name contains 3 to 36 characters. It must start and end with a lowercase letter or number. The value can contain lowercase letters, digits, and hyphens (-).",
        "zh-cn": "长度为3~36个字符。必须以小写英文字母或数字开头和结尾。可包含小写英文字母、数字和短划线(-)。"
      },
      "AssociationProperty": "AutoCompleteInput",
      "AssociationPropertyMetadata": {
        "Length": 5,
        "Prefix": "k8s-hpa-sls-project-",
        "CharacterClasses": [
          {
            "Class": "lowercase",
            "min": 1
          }
        ]
      }
    },
    "ManagedKubernetesClusterName": {
      "Type": "String",
      "Label": {
        "en": "Managed Kubernetes Cluster Name",
        "zh-cn": "ACK托管版集群名称"
      },
      "AssociationProperty": "AutoCompleteInput",
      "AssociationPropertyMetadata": {
        "Length": 5,
        "Prefix": "k8s-hpa-cluster-",
        "CharacterClasses": [
          {
            "Class": "lowercase",
            "min": 1
          }
        ]
      }
    },
    "ZoneId1": {
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",
      "AssociationPropertyMetadata": {
        "ExclusiveTo": [
          "ZoneId2"
        ]
      },
      "Label": {
        "en": "Availability Zone",
        "zh-cn": "可用区1"
      }
    },
    "ZoneId2": {
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",
      "AssociationPropertyMetadata": {
        "ExclusiveTo": [
          "ZoneId1"
        ]
      },
      "Label": {
        "en": "Availability Zone",
        "zh-cn": "可用区2"
      }
    },
    "InstanceType": {
      "Type": "CommaDelimitedList",
      "AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",
      "AssociationPropertyMetadata": {
        "InstanceChargeType": "PostPaid",
        "SystemDiskCategory": "cloud_essd",
        "CreateACKClusterParams": {
          "NetworkPlugin": "terway-eniip"
        }
      },
      "Label": {
        "en": "Instance Type",
        "zh-cn": "实例规格"
      }
    },
    "InstancePassword": {
      "NoEcho": true,
      "Type": "String",
      "Description": {
        "en": "Server login password, Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)",
        "zh-cn": "服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)"
      },
      "Label": {
        "en": "Instance Password",
        "zh-cn": "实例密码"
      },
      "ConstraintDescription": {
        "en": "Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)",
        "zh-cn": "长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)"
      },
      "AssociationProperty": "ALIYUN::ECS::Instance::Password",
      "Default": null
    }
  },
  "Resources": {
    "Vpc": {
      "Type": "ALIYUN::ECS::VPC",
      "Properties": {
        "CidrBlock": "10.0.0.0/8",
        "VpcName": {
          "Fn::Sub": "${CommonName}-vpc"
        }
      }
    },
    "VSwitch1": {
      "Type": "ALIYUN::ECS::VSwitch",
      "Properties": {
        "VpcId": {
          "Ref": "Vpc"
        },
        "CidrBlock": "10.0.0.0/24",
        "ZoneId": {
          "Ref": "ZoneId1"
        },
        "VSwitchName": {
          "Fn::Sub": "${CommonName}-vsw"
        }
      }
    },
    "VSwitch2": {
      "Type": "ALIYUN::ECS::VSwitch",
      "Properties": {
        "VpcId": {
          "Ref": "Vpc"
        },
        "CidrBlock": "10.0.1.0/24",
        "ZoneId": {
          "Ref": "ZoneId2"
        },
        "VSwitchName": {
          "Fn::Sub": "${CommonName}-vsw"
        }
      }
    },
    "SecurityGroup": {
      "Type": "ALIYUN::ECS::SecurityGroup",
      "Properties": {
        "VpcId": {
          "Ref": "Vpc"
        },
        "SecurityGroupName": {
          "Fn::Sub": "${CommonName}-sg"
        },
        "SecurityGroupIngress": [
          {
            "PortRange": "443/443",
            "SourceCidrIp": "0.0.0.0/0",
            "IpProtocol": "tcp"
          },
          {
            "PortRange": "80/80",
            "SourceCidrIp": "0.0.0.0/0",
            "IpProtocol": "tcp"
          }
        ]
      }
    },
    "SlsProject": {
      "Type": "ALIYUN::SLS::Project",
      "Properties": {
        "Name": {
          "Ref": "SlsProjectName"
        }
      }
    },
    "AliyunCSManagedAutoScalerRole": {
      "Type": "ALIYUN::RAM::Role",
      "Properties": {
        "RoleName": "AliyunCSManagedAutoScalerRole",
        "Description": "CS使用此角色来访问您在其他云产品中的资源。",
        "AssumeRolePolicyDocument": {
          "Version": "1",
          "Statement": [
            {
              "Action": "sts:AssumeRole",
              "Effect": "Allow",
              "Principal": {
                "Service": [
                  "cs.aliyuncs.com"
                ]
              }
            }
          ]
        },
        "MaxSessionDuration": 3600,
        "IgnoreExisting": true,
        "DeletionForce": true,
        "PolicyAttachments": {
          "System": [
            "AliyunCSManagedAutoScalerRolePolicy"
          ]
        }
      }
    },
    "AckCluster": {
      "Type": "ALIYUN::CS::ManagedKubernetesCluster",
      "DependsOn": "AliyunCSManagedAutoScalerRole",
      "Properties": {
        "VpcId": {
          "Ref": "Vpc"
        },
        "VSwitchIds": [
          {
            "Ref": "VSwitch1"
          },
          {
            "Ref": "VSwitch2"
          }
        ],
        "PodVswitchIds": [
          {
            "Ref": "VSwitch1"
          },
          {
            "Ref": "VSwitch1"
          }
        ],
        "Name": {
          "Ref": "ManagedKubernetesClusterName"
        },
        "KubernetesVersion": "1.31.1-aliyun.1",
        "ServiceCidr": "192.168.0.0/16",
        "ClusterSpec": "ack.pro.small",
        "LoadBalancerSpec": "slb.s2.small",
        "IsEnterpriseSecurityGroup": true,
        "SnatEntry": true,
        "NumOfNodes": 0,
        "EndpointPublicAccess": true,
        "Platform": "AliyunLinux",
        "Addons": [
          {
            "Name": "ack-node-local-dns"
          },
          {
            "Name": "terway-eniip",
            "Config": "{\"IPVlan\":\"false\",\"NetworkPolicy\":\"false\",\"ENITrunking\":\"false\"}"
          },
          {
            "Name": "csi-plugin"
          },
          {
            "Name": "csi-provisioner"
          },
          {
            "Name": "storage-operator",
            "Config": "{\"CnfsOssEnable\":\"false\",\"CnfsNasEnable\":\"false\"}"
          },
          {
            "Name": "nginx-ingress-controller",
            "Disabled": true
          },
          {
            "Name": "logtail-ds",
            "Config": "{\"IngressDashboardEnabled\":\"true\"}"
          },
          {
            "Name": "alb-ingress-controller",
            "Version": "",
            "Config": {
              "Fn::Sub": "{\"albIngress\":{\"AddressType\":\"Internet\",\"ZoneMappings\":{\"${ZoneId1}\":[\"${VSwitch1}\"], \"${ZoneId2}\":[\"${VSwitch2}\"]},\"CreateDefaultALBConfig\":true}}"
            }
          },
          {
            "Name": "ack-helm-manager"
          },
          {
            "Name": "arms-prometheus"
          }
        ],
        "ProxyMode": "ipvs",
        "DeleteOptions": [
          {
            "ResourceType": "ALB",
            "DeleteMode": "delete"
          },
          {
            "ResourceType": "SLB",
            "DeleteMode": "delete"
          },
          {
            "ResourceType": "SLS_Data",
            "DeleteMode": "delete"
          },
          {
            "ResourceType": "SLS_ControlPlane",
            "DeleteMode": "delete"
          },
          {
            "ResourceType": "PrivateZone",
            "DeleteMode": "delete"
          }
        ]
      }
    },
    "NodePools": {
      "Type": "ALIYUN::CS::ClusterNodePool",
      "Properties": {
        "ClusterId": {
          "Ref": "AckCluster"
        },
        "NodePoolInfo": {
          "Name": "k8s-hpa-cluster-nodepool"
        },
        "ScalingGroup": {
          "VSwitchIds": [
            {
              "Ref": "VSwitch1"
            },
            {
              "Ref": "VSwitch2"
            }
          ],
          "ZoneIds": [
            {
              "Ref": "ZoneId1"
            },
            {
              "Ref": "ZoneId2"
            }
          ],
          "SystemDiskCategory": "cloud_essd",
          "SystemDiskPerformanceLevel": "PL0",
          "SystemDiskSize": 40,
          "InstanceTypes": {
            "Ref": "InstanceType"
          },
          "LoginPassword": {
            "Ref": "InstancePassword"
          },
          "Platform": "AliyunLinux",
          "ImageId": "aliyun_3_9_x64_20G_alibase_20231219.vhd"
        },
        "KubernetesConfig": {
          "Runtime": "containerd",
          "RuntimeVersion": "1.6.28"
        },
        "AutoScaling": {
          "Enable": true,
          "MinInstances": 2,
          "MaxInstances": 10
        }
      }
    },
    "Sleep": {
      "Type": "ALIYUN::ROS::Sleep",
      "DependsOn": "NodePools",
      "Properties": {
        "CreateDuration": 300
      }
    },
    "AckMetricsAdapter": {
      "Type": "ALIYUN::CS::ClusterHelmApplication",
      "DependsOn": "Sleep",
      "Properties": {
        "Namespace": "kube-system",
        "ChartUrl": "https://aliacs-app-catalog.oss-cn-hangzhou.aliyuncs.com/charts-incubator/ack-alibaba-cloud-metrics-adapter-1.3.3.tgz",
        "ClusterId": {
          "Ref": "AckCluster"
        },
        "Name": "ack-alibaba-cloud-metrics-adapter",
        "ChartValues": {
          "AlibabaCloudMetricsAdapter": {
            "commonLabels": "",
            "replicas": 1,
            "resources": {
              "metricsAdapterDeployment": {
                "resources": {
                  "limits": {
                    "cpu": 0.5,
                    "memory": "1Gi"
                  },
                  "requests": {
                    "cpu": "100m",
                    "memory": "200Mi"
                  }
                }
              },
              "configReloader": {
                "resources": {
                  "limits": {
                    "cpu": "20m",
                    "memory": "30Mi"
                  },
                  "requests": {
                    "cpu": "20m",
                    "memory": "30Mi"
                  }
                }
              }
            },
            "listenPort": 443,
            "costWeights": {
              "cpu": "1.0",
              "memory": "0.0"
            },
            "image": {
              "repository": "registry-cn-hangzhou-vpc.ack.aliyuncs.com/acs/alibaba-cloud-metrics-adapter-amd64",
              "tag": "v0.2.7-f1ee5c3-aliyun",
              "pullPolicy": "Always"
            },
            "nameOverride": "",
            "fullnameOverride": "",
            "service": {
              "type": "ClusterIP"
            },
            "serviceAccountName": "ack-alibaba-cloud-metrics-adapter",
            "annotations": {},
            "nodeSelector": {},
            "tolerations": [],
            "env": [
              {
                "AccessKeyId": ""
              },
              {
                "AccessKeySecret": ""
              },
              {
                "Region": ""
              }
            ],
            "affinity": {},
            "prometheus": {
              "enabled": true,
              "url": {},
              "metricsRelistInterval": "1m",
              "logLevel": 5,
              "adapter": {
                "rules": {
                  "default": false,
                  "custom": [
                    {
                      "seriesQuery": "container_memory_working_set_bytes{namespace!=\"\",pod!=\"\"}",
                      "resources": {
                        "overrides": {
                          "namespace": {
                            "resource": "namespace"
                          },
                          "pod": {
                            "resource": "pod"
                          }
                        }
                      },
                      "name": {
                        "matches": "^(.*)_bytes",
                        "as": "${1}_bytes_per_second"
                      },
                      "metricsQuery": "sum(<<.Series>>{<<.LabelMatchers>>}) by (<<.GroupBy>>)"
                    },
                    {
                      "seriesQuery": "container_cpu_usage_seconds_total{namespace!=\"\",pod!=\"\"}",
                      "resources": {
                        "overrides": {
                          "namespace": {
                            "resource": "namespace"
                          },
                          "pod": {
                            "resource": "pod"
                          }
                        }
                      },
                      "name": {
                        "matches": "^(.*)_seconds_total",
                        "as": "${1}_core_per_second"
                      },
                      "metricsQuery": "sum(rate(<<.Series>>{<<.LabelMatchers>>}[1m])) by (<<.GroupBy>>)"
                    }
                  ]
                }
              }
            }
          },
          "ConfigReloader": {
            "image": {
              "repository": "registry-vpc.cn-hangzhou.aliyuncs.com/acs/configmap-reload",
              "tag": "v0.0.1"
            }
          }
        }
      }
    },
    "InstallBackendApp": {
      "Type": "ALIYUN::CS::ClusterApplication",
      "DependsOn": "AckMetricsAdapter",
      "Properties": {
        "ClusterId": {
          "Ref": "AckCluster"
        },
        "YamlContent": {
          "Fn::Sub": "apiVersion: apps/v1\nkind: Deployment\nmetadata:\n  name: coffee\nspec:\n  replicas: 2\n  selector:\n    matchLabels:\n      app: coffee\n  template:\n    metadata:\n      labels:\n        app: coffee\n    spec:\n      containers:\n      - name: coffee\n        image: registry.${ALIYUN::Region}.aliyuncs.com/acs-sample/nginxdemos:latest\n        ports:\n        - containerPort: 80\n        resources:\n          limits:\n            cpu: 500m\n            memory: 1Gi\n          requests:\n            cpu: 500m\n            memory: 512Mi\n---\napiVersion: v1\nkind: Service\nmetadata:\n  name: coffee-svc\nspec:\n  ports:\n  - port: 80\n    targetPort: 80\n    protocol: TCP\n  selector:\n    app: coffee\n  type: NodePort\n---\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n  name: tea\nspec:\n  replicas: 2\n  selector:\n    matchLabels:\n      app: tea\n  template:\n    metadata:\n      labels:\n        app: tea\n    spec:\n      containers:\n      - name: tea\n        image: registry.${ALIYUN::Region}.aliyuncs.com/acs-sample/nginxdemos:latest\n        ports:\n        - containerPort: 80\n        resources:\n          limits:\n            cpu: 500m\n            memory: 1Gi\n          requests:\n            cpu: 500m\n            memory: 512Mi\n---\napiVersion: v1\nkind: Service\nmetadata:\n  name: tea-svc\nspec:\n  ports:\n  - port: 80\n    targetPort: 80\n    protocol: TCP\n  selector:\n    app: tea\n  type: NodePort"
        }
      }
    },
    "AlbConfig": {
      "Type": "ALIYUN::CS::ClusterApplication",
      "DependsOn": "InstallBackendApp",
      "Properties": {
        "ClusterId": {
          "Ref": "AckCluster"
        },
        "YamlContent": {
          "Fn::Sub": "apiVersion: alibabacloud.com/v1\nkind: AlbConfig\nmetadata:\n  name: k8s-hpa-alb-config\nspec:\n  config:\n    name: k8s-hpa-alb\n    addressType: Internet\n    zoneMappings:\n    - vSwitchId: ${VSwitch1}\n    - vSwitchId: ${VSwitch2}\n    accessLogConfig:\n      logProject: ${SlsProject}\n      logStore: \"alb_k8s_hpa_sls_logstore\"\n  listeners:\n    - port: 80\n      protocol: HTTP"
        }
      }
    },
    "IngressClass": {
      "Type": "ALIYUN::CS::ClusterApplication",
      "DependsOn": "AlbConfig",
      "Properties": {
        "ClusterId": {
          "Ref": "AckCluster"
        },
        "YamlContent": {
          "Fn::Sub": "apiVersion: networking.k8s.io/v1\nkind: IngressClass\nmetadata:\n  name: k8s-hpa-alb-ingress-class\nspec:\n  controller: ingress.k8s.alibabacloud/alb\n  parameters:\n    apiGroup: alibabacloud.com\n    kind: AlbConfig\n    name: k8s-hpa-alb-config"
        }
      }
    },
    "Ingress": {
      "Type": "ALIYUN::CS::ClusterApplication",
      "DependsOn": "IngressClass",
      "Properties": {
        "ClusterId": {
          "Ref": "AckCluster"
        },
        "YamlContent": {
          "Fn::Sub": "apiVersion: networking.k8s.io/v1\nkind: Ingress\nmetadata:\n  name: k8s-hpa-alb-ingress\nspec:\n  ingressClassName: k8s-hpa-alb-ingress-class\n  rules:\n   - http:\n      paths:\n      - path: /tea\n        pathType: ImplementationSpecific\n        backend:\n          service:\n            name: tea-svc\n            port:\n              number: 80\n      - path: /coffee\n        pathType: ImplementationSpecific\n        backend:\n          service:\n            name: coffee-svc\n            port: \n              number: 80"
        }
      }
    },
    "Hpa": {
      "Type": "ALIYUN::CS::ClusterApplication",
      "DependsOn": "WaitAlbIngress",
      "Properties": {
        "ClusterId": {
          "Ref": "AckCluster"
        },
        "YamlContent": {
          "Fn::Sub": "apiVersion: autoscaling/v2\nkind: HorizontalPodAutoscaler\nmetadata:\n  name: k8s-alb-tea-hpa\nspec:\n  scaleTargetRef:\n    apiVersion: apps/v1\n    kind: Deployment\n    name: tea\n  minReplicas: 2\n  maxReplicas: 10\n  metrics:\n    - type: External\n      external:\n        metric:\n          name: sls_alb_ingress_qps\n          selector:\n            matchLabels:\n              sls.project: ${SlsProject}\n              sls.logstore: \"alb_k8s_hpa_sls_logstore\" \n              sls.ingress.route: \"default-tea-svc-80\"\n        target:\n          type: AverageValue\n          averageValue: 2\n    - resource:\n        name: cpu\n        target:\n          averageUtilization: 80\n          type: Utilization\n      type: Resource\n    - resource:\n        name: memory\n        target:\n          averageUtilization: 80\n          type: Utilization\n      type: Resource"
        }
      }
    },
    "WaitAlbIngress": {
      "Type": "ALIYUN::ROS::Sleep",
      "DependsOn": "Ingress",
      "Properties": {
        "CreateDuration": 120
      }
    },
    "IngressInfo": {
      "Type": "DATASOURCE::CS::ClusterApplicationResources",
      "DependsOn": "WaitAlbIngress",
      "Properties": {
        "ClusterId": {
          "Ref": "AckCluster"
        },
        "Kind": "Ingress",
        "Namespace": "default",
        "JsonPath": "$.items.[0].status.loadBalancer.ingress.[0].hostname",
        "FirstMatch": true
      }
    }
  },
  "Outputs": {
    "TeaUrl": {
      "Description": {
        "zh-cn": "tea服务访问地址。",
        "en": "The addresses of tea service."
      },
      "Value": {
        "Fn::Sub": "http://${IngressInfo}/tea"
      }
    },
    "CoffeeUrl": {
      "Description": {
        "zh-cn": "coffee服务访问地址。",
        "en": "The addresses of coffee service."
      },
      "Value": {
        "Fn::Sub": "http://${IngressInfo}/coffee"
      }
    }
  },
  "Metadata": {
    "ALIYUN::ROS::Interface": {
      "ParameterGroups": [
        {
          "Parameters": [
            "SlsProjectName",
            "ManagedKubernetesClusterName",
            "ZoneId1",
            "ZoneId2",
            "InstanceType",
            "InstancePassword"
          ]
        }
      ],
      "TemplateTags": [
        "acs:technical-solution:micro:通过HPA实现容器应用的水平弹性伸缩-tech_solu_125"
      ],
      "Hidden": [
        "CommonName"
      ]
    }
  }
}