@@ -51,6 +51,19 @@ title: "如何创建 TKE 集群"
5151| RunInstancesForNode | 否 | Array | 节点创建参数 | 见下方 |
5252| Region | 是 | String | 地域 | ap-guangzhou |
5353
54+ ** ClusterBasicSettings 常用参数** :
55+
56+ | 参数名 | 必填 | 类型 | 说明 | 示例值 |
57+ | --------| ------| ------| ------| --------|
58+ | ClusterName | 否 | String | 集群名称,建议不超过 50 个字符 | my-tke-cluster |
59+ | ClusterVersion | 否 | String | Kubernetes 版本 | 1.28.3 |
60+ | ClusterDescription | 否 | String | 集群描述 | 生产集群 |
61+ | VpcId | 否 | String | VPC ID | vpc-xxxxxxxx |
62+ | ProjectId | 否 | Integer | 项目 ID,默认 0 | 0 |
63+ | TagSpecification | 否 | Array | 集群资源标签配置 | 见下方 |
64+ | ClusterLevel | 否 | String | 集群规模: L5/L20/L50/L100/L200/L500 | L5 |
65+ | AutoUpgradeClusterLevel | 否 | Object | 集群规格自动升配配置 | ` {"IsAutoUpgrade": true} ` |
66+
5467** ClusterCIDRSettings 结构** :
5568
5669``` text
@@ -71,13 +84,51 @@ title: "如何创建 TKE 集群"
7184 "ClusterDescription": "测试集群", // 集群描述
7285 "VpcId": "vpc-xxxxxxxx", // VPC ID
7386 "ProjectId": 0, // 项目ID (默认0)
87+ "TagSpecification": [ // 集群资源标签
88+ {
89+ "ResourceType": "cluster",
90+ "Tags": [
91+ {"Key": "env", "Value": "production"},
92+ {"Key": "owner", "Value": "platform-team"}
93+ ]
94+ }
95+ ],
7496 "ClusterLevel": "L5", // 集群规模: L5/L20/L50/L100/L200/L500
7597 "AutoUpgradeClusterLevel": { // 集群规格自动升配配置
7698 "IsAutoUpgrade": true // 是否自动升配
7799 }
78100}
79101```
80102
103+ ** TagSpecification 结构** :
104+
105+ ``` text
106+ [
107+ {
108+ "ResourceType": "cluster", // 标签绑定的资源类型,创建集群时固定为 cluster
109+ "Tags": [
110+ {
111+ "Key": "env", // 标签键
112+ "Value": "production" // 标签值
113+ },
114+ {
115+ "Key": "owner",
116+ "Value": "platform-team"
117+ }
118+ ]
119+ }
120+ ]
121+ ```
122+
123+ 常用标签建议:
124+
125+ | 标签键 | 示例值 | 用途 |
126+ | --------| --------| ------|
127+ | env | production / staging / test | 区分环境 |
128+ | owner | platform-team | 标识责任团队 |
129+ | cost-center | cc-1001 | 成本分摊 |
130+ | project | payment | 关联业务项目 |
131+
81132#### Step 2: 调用 CreateCluster API
82133
83134** 使用 cURL (HTTP 直接调用)** :
@@ -103,7 +154,16 @@ curl -X POST "https://tke.tencentcloudapi.com/" \
103154 "ClusterLevel": "L5",
104155 "AutoUpgradeClusterLevel": {
105156 "IsAutoUpgrade": true
106- }
157+ },
158+ "TagSpecification": [
159+ {
160+ "ResourceType": "cluster",
161+ "Tags": [
162+ {"Key": "env", "Value": "production"},
163+ {"Key": "owner", "Value": "platform-team"}
164+ ]
165+ }
166+ ]
107167 },
108168 "ClusterCIDRSettings": {
109169 "ClusterCIDR": "172.16.0.0/16",
@@ -130,7 +190,16 @@ tccli tke CreateCluster \
130190 "ClusterLevel": "L5",
131191 "AutoUpgradeClusterLevel": {
132192 "IsAutoUpgrade": true
133- }
193+ },
194+ "TagSpecification": [
195+ {
196+ "ResourceType": "cluster",
197+ "Tags": [
198+ {"Key": "env", "Value": "production"},
199+ {"Key": "owner", "Value": "platform-team"}
200+ ]
201+ }
202+ ]
134203 }' \
135204 --ClusterCIDRSettings ' {
136205 "ClusterCIDR": "172.16.0.0/16",
@@ -158,6 +227,16 @@ req.ClusterBasicSettings = models.ClusterBasicSettings()
158227req.ClusterBasicSettings.ClusterName = " my-tke-cluster"
159228req.ClusterBasicSettings.ClusterVersion = " 1.28.3"
160229req.ClusterBasicSettings.VpcId = " vpc-xxxxxxxx"
230+ tag_spec = models.TagSpecification()
231+ tag_spec.ResourceType = " cluster"
232+ env_tag = models.Tag()
233+ env_tag.Key = " env"
234+ env_tag.Value = " production"
235+ owner_tag = models.Tag()
236+ owner_tag.Key = " owner"
237+ owner_tag.Value = " platform-team"
238+ tag_spec.Tags = [env_tag, owner_tag]
239+ req.ClusterBasicSettings.TagSpecification = [tag_spec]
161240req.ClusterBasicSettings.ClusterLevel = " L5"
162241req.ClusterBasicSettings.AutoUpgradeClusterLevel = models.AutoUpgradeClusterLevel()
163242req.ClusterBasicSettings.AutoUpgradeClusterLevel.IsAutoUpgrade = True
@@ -197,6 +276,15 @@ func main() {
197276 ClusterName: common.StringPtr (" my-tke-cluster" ),
198277 ClusterVersion: common.StringPtr (" 1.28.3" ),
199278 VpcId: common.StringPtr (" vpc-xxxxxxxx" ),
279+ TagSpecification: []*tke.TagSpecification {
280+ {
281+ ResourceType: common.StringPtr (" cluster" ),
282+ Tags: []*tke.Tag {
283+ {Key: common.StringPtr (" env" ), Value: common.StringPtr (" production" )},
284+ {Key: common.StringPtr (" owner" ), Value: common.StringPtr (" platform-team" )},
285+ },
286+ },
287+ },
200288 ClusterLevel: common.StringPtr (" L5" ),
201289 AutoUpgradeClusterLevel: &tke.AutoUpgradeClusterLevel {
202290 IsAutoUpgrade: common.BoolPtr (true ),
@@ -382,6 +470,31 @@ CoreDNS is running at https://cls-xxxxxxxx.ccs.tencent-cloud.com/api/v1/namespac
382470
383471` AutoUpgradeClusterLevel ` 是对象类型,不是布尔值;当前 CreateCluster API 示例使用 ` {"IsAutoUpgrade": true} ` 。
384472
473+ ### 配置集群标签
474+
475+ 创建集群时可以通过 ` ClusterBasicSettings.TagSpecification ` 同步绑定标签到集群实例:
476+
477+ ``` json
478+ {
479+ "ClusterBasicSettings" : {
480+ "ClusterName" : " prod-payment-gz" ,
481+ "TagSpecification" : [
482+ {
483+ "ResourceType" : " cluster" ,
484+ "Tags" : [
485+ {"Key" : " env" , "Value" : " production" },
486+ {"Key" : " project" , "Value" : " payment" },
487+ {"Key" : " cost-center" , "Value" : " cc-1001" }
488+ ]
489+ }
490+ ]
491+ }
492+ }
493+ ```
494+
495+ !!! note "标签说明"
496+ ` ResourceType ` 创建集群时使用 ` cluster ` 。标签用于资源检索、权限治理和成本分摊,建议在创建时一次性写入基础标签,避免后续补录遗漏。
497+
385498### 配置集群删除保护
386499
387500创建后通过 API 启用:
@@ -408,6 +521,7 @@ tccli tke EnableClusterDeletionProtection \
408521- 容器网络 CIDR: 172.16.0.0/16
409522- Service CIDR: 10.96.0.0/24
410523- 集群规模: L5
524+ - 集群标签: env=production, owner=platform-team, cost-center=cc-1001
411525```
412526
413527### 带节点创建 Prompt
@@ -437,7 +551,11 @@ tccli tke EnableClusterDeletionProtection \
437551 - L20: 6-20 节点,适合小型生产
438552 - L50: 21-50 节点,适合中型生产
4395534 . ** 启用删除保护** : 生产集群建议启用删除保护
440- 5 . ** 版本选择** : 选择稳定版本,避免使用最新版本
554+ 5 . ** 标签策略** :
555+ - 创建时添加 ` env ` 、` owner ` 、` project ` 、` cost-center ` 等基础标签
556+ - 标签键和值保持稳定,避免同一含义出现 ` team ` 、` owner ` 、` department ` 等多套命名
557+ - 结合 CAM、账单和资源检索需求提前约定标签规范
558+ 6 . ** 版本选择** : 选择稳定版本,避免使用最新版本
441559
442560---
443561
0 commit comments