文档首页/ 云容器引擎 CCE/ API参考/ API/ 集群管理/ 更新指定的集群 - UpdateCluster
更新时间:2026-08-24 GMT+08:00
分享

更新指定的集群 - UpdateCluster

功能介绍

该API用于更新指定的集群。

集群管理的URL格式为:https://Endpoint/uri。其中uri为资源路径,也即API访问的路径。

调用方法

请参见如何调用API

授权信息

账号具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备调用API所需的权限。

  • 如果使用角色与策略授权,具体权限要求请参见权限和授权项
  • 如果使用身份策略授权,需具备如下身份策略权限。

    授权项

    访问级别

    资源类型(*为必须)

    条件键

    别名

    依赖的授权项

    cce:cluster:updateCluster

    Write

    cluster *

    • g:EnterpriseProjectId

    • g:ResourceTag/<tag-key>

    cce:cluster:update

    -

URI

PUT /api/v3/projects/{project_id}/clusters/{cluster_id}

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数解释:

项目ID,获取方式请参见如何获取接口URI中参数

约束限制:

不涉及

取值范围:

账号的项目ID

默认取值:

不涉及

cluster_id

String

参数解释:

集群ID,获取方式请参见如何获取接口URI中参数

约束限制:

不涉及

取值范围:

集群ID

默认取值:

不涉及

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

Content-Type

String

参数解释:

消息体的类型(格式),默认为application/json,有其他取值时会在具体接口中专门说明。

约束限制:

GET方法不做校验

取值范围:

不涉及

默认取值:

不涉及

X-Auth-Token

String

参数解释:

调用接口的认证方式分为Token和AK/SK两种,如果您使用的Token方式,此参数为必填,请填写Token的值,获取方式请参见获取token

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

表3 请求Body参数

参数

是否必选

参数类型

描述

spec

ClusterInformationSpec object

参数解释:

具体集群参数。

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

metadata

ClusterMetadataForUpdate object

参数解释:

集群基本信息,包含与名称相关的字段。

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

表4 ClusterInformationSpec

参数

是否必选

参数类型

描述

agencyName

String

参数解释:

指定集群使用的委托。该委托用于生成集群中组件使用的临时访问凭证,在集群中自动创建其他相关云服务的资源时会使用该委托权限。当不传或为空时,集群将自动选择使用CCE的系统委托cce_admin_trust或cce_cluster_agency。

说明:
关于CCE系统委托的说明详情参见系统委托说明

约束限制:

仅1.27及以上版本集群支持该参数

取值范围:

不涉及

默认取值:

description

String

参数解释:

集群的描述信息。

约束限制:

仅运行和扩容状态(Available、ScalingUp、ScalingDown)的集群允许修改。

取值范围:

字符取值范围[0,200]。不包含~$%^&*<>[]{}()'"#\等特殊字符。

默认取值:

customSan

Array of strings

参数解释:

集群的API Server服务端证书中的自定义SAN(Subject Alternative Name)字段,遵从SSL标准X509定义的格式规范。

约束限制:

不允许出现同名重复。

取值范围:

格式符合IP和域名格式。

默认取值:

不涉及

示例:

SAN 1: DNS Name=example.com
SAN 2: DNS Name=www.example.com
SAN 3: DNS Name=example.net
SAN 4: IP Address=93.184.216.34

containerNetwork

ContainerNetworkUpdate object

参数解释:

容器网络参数,包含容器网段的信息。

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

eniNetwork

EniNetworkUpdate object

参数解释:

云原生网络2.0网络配置,包含CCE Turbo集群的容器子网信息。

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

deletionProtection

Boolean

参数解释:

集群删除保护,如果开启后用户将无法删除该集群。

约束限制:

不涉及

取值范围:

  • true: 开启集群删除保护

  • false: 关闭集群删除保护

默认取值:

默认false

hostNetwork

hostNetwork object

参数解释:

节点网络参数,包含了Node节点默认安群组设置。

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

secretConfig

SecretConfigUpdate object

参数解释

secret禁用配置,控制是否在集群中禁用以Secret形式静态存储的临时凭据。

约束限制

支持的集群版本如下:

  • v1.28.15-r90及以上版本

  • v1.29.15-r50及以上版本

  • v1.30.14-r50及以上版本

  • v1.31.14-r10及以上版本

  • v1.32.9-r10及以上版本

  • v1.33.7-r10及以上版本

  • v1.34.3-r0及以上版本

取值范围

不涉及

默认取值

不涉及

表5 ContainerNetworkUpdate

参数

是否必选

参数类型

描述

cidrs

Array of ContainerCIDR objects

参数解释:

容器网络网段列表。1.21及新版本集群,当集群网络类型为vpc-router时,支持增量添加容器网段,最多配置20个。

约束限制:

此参数在集群更新后不可更改,请谨慎选择。(已废弃,建议使用containercidrs字段替代)

取值范围:

不涉及

默认取值:

不涉及

containercidrs

Array of strings

参数解释:

容器网络网段列表。当集群网络类型为vpc-router时,支持添加或删除容器网段。支持的集群版本如下:

  • v1.28.15-r60及以上版本

  • v1.29.15-r20及以上版本

  • v1.30.14-r20及以上版本

  • v1.31.10-r20及以上版本

  • v1.32.6-r20及以上版本

  • v1.33.5-r10及以上版本

支持修改集群容器网段的顺序,顺序在前的容器网段优先被使用。

约束限制:

  • 最多支持配置20个子网。

  • 填写为空时,该字段不生效。

取值范围:

不涉及

默认取值:

不涉及

表6 ContainerCIDR

参数

是否必选

参数类型

描述

cidr

String

参数解释:

容器网络网段,建议使用网段10.0.0.0/12~19,172.16.0.0/16~19,192.168.0.0/16~19。

约束限制:

如存在网段冲突,将会报错。

取值范围:

不涉及

默认取值:

不涉及

表7 EniNetworkUpdate

参数

是否必选

参数类型

描述

subnets

Array of NetworkSubnet objects

参数解释:

IPv4子网ID列表。1.19.10及以上版本的CCE Turbo集群支持多容器子网,同时支持增量更新容器子网列表。

约束限制:

请求体中需包含所有已经存在的subnet。

取值范围:

不涉及

默认取值:

不涉及

表8 NetworkSubnet

参数

是否必选

参数类型

描述

subnetID

String

参数解释:

用于创建容器网卡的子网的IPv4子网ID。

约束限制:

暂不支持IPv6

取值范围:

不涉及

默认取值:

不涉及

获取方法如下:

  • 方法1:登录虚拟私有云服务的控制台界面,单击VPC下的子网,进入子网详情页面,查找IPv4子网ID。

  • 方法2:通过虚拟私有云服务的查询子网列表接口查询,获取响应中neutron_subnet_id字段的值。

链接请参见查询子网列表

表9 hostNetwork

参数

是否必选

参数类型

描述

SecurityGroup

String

参数解释:

集群默认Node节点安全组需要放通部分端口来保证正常通信,详细设置请参考集群安全组规则配置

约束限制:

修改后的安全组只作用于新创建的节点和新纳管的节点,存量节点的安全组需手动修改。

取值范围:

不涉及

默认取值:

不涉及

表10 SecretConfigUpdate

参数

是否必选

参数类型

描述

disableDefaultAddonCredSecret

Boolean

参数解释:

是否在集群中禁用默认插件凭证(paas.elb、paas.aksk secret)。该Secret的data内容是临时AK/SK数据,部分插件在未配置自定义委托时会使用它作为IAM凭证访问其他云服务。

更多信息请参见禁用集群中静态存储的临时凭据说明

约束限制:

仅当集群中所有需要访问云服务的插件均已配置自定义委托后,才能禁用该Secret。

取值范围:

  • true: 禁用

  • false: 启用

默认取值:

不涉及,未指定则不更新此参数

disableNodeAgencyCredSecret

Boolean

参数解释:

是否在集群中禁用节点凭证(node-agency-cred secret)。该Secret的data内容是临时AK/SK数据,节点上安装的系统组件默认使用该凭证。

更多信息请参见禁用集群中静态存储的临时凭据说明

约束限制:

需确保已为每个节点/节点池配置委托,且委托至少具备cce:node:get、cce::assumeAgencyForPodIdentity权限,否则禁用该Secret会导致节点安装、运行异常。

取值范围:

  • true: 禁用

  • false: 启用

默认取值:

false

disableDefaultImagePullSecret

Boolean

参数解释:

是否在集群中禁用默认镜像访问凭证(default-secret secret)。该Secret的data内容是SWR临时登录指令,用于SWR的私有镜像拉取。

更多信息请参见禁用集群中静态存储的临时凭据说明

约束限制:

需确保集群中的工作负载不使用default-secret作为镜像拉取凭证(配置了镜像免密下载或者使用自定义镜像拉取凭证),否则禁用该Secret后可能会导致镜像拉取失败。

取值范围:

  • true: 禁用

  • false: 启用

默认取值:

false

表11 ClusterMetadataForUpdate

参数

是否必选

参数类型

描述

alias

String

参数解释:

集群显示名。

约束限制:

显示名和其他集群的名称、显示名不可以重复。

取值范围:

命名规则:以中文或英文字符开头,由数字、中文、英文字符、中划线(-)组成,长度范围 4-128位,且不能以中划线(-)开头和结尾。

为空时表示不进行修改。

默认取值:

不涉及

响应参数

状态码:200

表12 响应Body参数

参数

参数类型

描述

kind

String

参数解释:

API类型。

取值范围:

  • Cluster

  • cluster

apiVersion

String

参数解释:

API版本。

取值范围:

  • v3

metadata

ClusterMetadata object

参数解释:

集群的基本信息,为集合类的元素类型,包含一组由不同名称定义的属性。

spec

ClusterSpec object

参数解释:

spec是集合类的元素类型,您对需要管理的集群对象进行详细描述的主体部分都在spec中给出。CCE通过spec的描述来创建或更新对象。

status

ClusterStatus object

参数解释:

不涉及集合类的元素类型,用于记录对象在系统中的当前状态信息,包含了集群状态和本次创建集群作业的jobID

表13 ClusterMetadata

参数

参数类型

描述

name

String

参数解释:

集群名称。

取值范围:

以小写字母开头,由小写字母、数字、中划线(-)组成,长度范围4-128位,且不能以中划线(-)结尾。

uid

String

参数解释:

集群ID,资源唯一标识。

取值范围:

不涉及

alias

String

参数解释:

集群显示名,用于在 CCE 界面显示,该名称创建后可修改。显示名和其他集群的名称、显示名不可以重复。

取值范围:

以中文或英文字符开头,由数字、中文、英文字符、中划线(-)组成,长度范围 4-128位,且不能以中划线(-)开头和结尾。

annotations

Map<String,String>

参数解释:

集群注解,由key/value组成:

"annotations": {
   "key1" : "value1",
   "key2" : "value2"
}

取值范围:

不涉及

labels

Map<String,String>

参数解释:

集群标签,key/value对格式。

取值范围:

不涉及

creationTimestamp

String

参数解释:

集群创建时间。

取值范围:

不涉及

updateTimestamp

String

参数解释:

集群更新时间。

取值范围:

不涉及

timezone

String

参数解释:

集群时区。IANA Time Zone Database中收录的时区名称, 例如:"Asia/Shanghai"。

取值范围:

不涉及

表14 ClusterSpec

参数

参数类型

描述

category

String

参数解释:

集群类别。

取值范围:

  • CCE:CCE集群

  • Turbo: CCE Turbo集群。

CCE集群支持虚拟机与裸金属服务器混合、GPU、NPU等异构节点的混合部署,基于高性能网络模型提供全方位、多场景、安全稳定的容器运行环境。

全面基于云原生基础设施构建的云原生2.0的容器引擎服务,具备软硬协同、网络无损、安全可靠、调度智能的优势,为用户提供一站式、高性价比的全新容器服务体验。

agencyName

String

参数解释:

指定集群使用的委托。该委托用于生成集群中组件使用的临时访问凭证,在集群中自动创建其他相关云服务的资源时会使用该委托权限。当不传或为空时,集群将自动选择使用CCE的系统委托cce_admin_trust或cce_cluster_agency。

说明:
关于CCE系统委托的说明详情参见系统委托说明

取值范围:

不涉及

type

String

参数解释:

集群Master节点架构

取值范围:

  • VirtualMachine:Master节点为x86架构服务器

  • ARM64: Master节点为鲲鹏(ARM架构)服务器

flavor

String

参数解释:

集群规格,当集群为v1.15及以上版本时支持创建后变更,详情请参见变更集群规格。请按实际业务需求进行选择

取值范围:

  • cce.s1.small: 小规模单控制节点CCE集群(最大50节点)

  • cce.s1.medium: 中等规模单控制节点CCE集群(最大200节点)

  • cce.s1.large: 大规模单控制节点CCE集群(最大1000节点)

  • cce.s2.small: 小规模三控制节点CCE集群(最大50节点)

  • cce.s2.medium: 中等规模三控制节点CCE集群(最大200节点)

  • cce.s2.large: 大规模三控制节点CCE集群(最大1000节点)

  • cce.s2.xlarge: 超大规模三控制节点CCE集群(最大2000节点)

专属云特殊规格如下:

  • cce.dec.s1.small: 小规模单控制节点的专属云CCE集群(最大50节点)

  • cce.dec.s1.medium: 中等规模单控制节点的专属云CCE集群(最大200节点)

  • cce.dec.s1.large: 大规模单控制节点的专属云CCE集群(最大1000节点)

  • cce.dec.s1.xlarge: 超大规模单控制节点的专属云CCE集群(最大2000节点)

  • cce.dec.s2.small: 小规模三控制节点的专属云CCE集群(最大50节点)

  • cce.dec.s2.medium: 中等规模三控制节点的专属云CCE集群(最大200节点)

  • cce.dec.s2.large: 大规模三控制节点的专属云CCE集群(最大1000节点)

  • cce.dec.s2.xlarge: 超大规模三控制节点的专属云CCE集群(最大2000节点)

version

String

参数解释:

集群版本,与Kubernetes社区基线版本保持一致,建议选择最新商用版本。

说明:
关于Kubernetes版本策略,请参见Kubernetes版本策略

在CCE控制台支持创建三种最新版本的集群。可登录CCE控制台创建集群,在“版本”处获取到集群版本。

其它集群版本,当前仍可通过api创建,但后续会逐渐下线,具体下线策略请关注CCE官方公告。

取值范围:

不涉及

platformVersion

String

参数解释:

CCE集群平台版本号,表示集群版本(version)下的内部版本。用于跟踪某一集群版本内的迭代,集群版本内唯一,跨集群版本重新计数。

取值范围:

platformVersion格式为:cce.X.Y

  • X: 表示内部特性版本。集群版本中特性或者补丁修复,或者OS支持等变更场景。其值从1开始单调递增。

  • Y: 表示内部特性版本的补丁版本。仅用于特性版本上线后的软件包更新,不涉及其他修改。其值从0开始单调递增。

legacyVersion

String

参数解释:

CCE集群旧版本(已废弃),无实际功能,仅用于集群version与platformVersion组合展示,该版本号全局内唯一。如集群version为va.b, platformVersion为cce.X.Y,则legacyVersion值为va.b.X-rY。

取值范围:

不涉及

description

String

参数解释:

集群描述,对于集群使用目的的描述,可根据实际情况自定义,默认为空。集群创建成功后可通过接口更新指定的集群来做出修改,也可在CCE控制台中对应集群的“集群详情”下的“描述”处进行修改。

取值范围:

不涉及

customSan

Array of strings

参数解释:

集群的API Server服务端证书中的自定义SAN(Subject Alternative Name)字段,遵从SSL标准X509定义的格式规范。

取值范围:

格式符合IP和域名格式。

ipv6enable

Boolean

参数解释:

集群是否使用IPv6模式,1.15版本及以上支持。

取值范围:

  • true: 开启IPv4/IPv6双栈模式

  • false: 仅使用IPv4模式

hostNetwork

HostNetwork object

参数解释:

节点网络参数,包含了虚拟私有云VPC和子网的ID信息,而VPC是集群内节点之间的通信依赖,所以是必选的参数集。

containerNetwork

ContainerNetwork object

参数解释:

容器网络参数,包含了容器网络类型和容器网段的信息。

eniNetwork

EniNetwork object

参数解释:

云原生网络2.0网络配置,创建CCE Turbo集群时指定。

serviceNetwork

ServiceNetwork object

参数解释:

服务网段参数,包含IPv4 CIDR。

publicAccess

PublicAccess object

参数解释:

集群API访问控制。

authentication

Authentication object

参数解释:

集群认证方式相关配置。

billingMode

Integer

参数解释:

集群的计费方式。

取值范围:

  • 0: 按需计费

  • 1: 包周期

masters

Array of MasterSpec objects

参数解释:

集群控制节点的高级配置,支持指定控制节点的可用区。

kubernetesSvcIpRange

String

参数解释:

服务网段参数,kubernetes clusterIP取值范围,1.11.7版本及以上支持。创建集群时如若未传参,默认为"10.247.0.0/16"。该参数废弃中,推荐使用新字段serviceNetwork,包含IPv4服务网段。

取值范围:

不涉及

clusterTags

Array of ResourceTag objects

参数解释:

集群资源标签。

kubeProxyMode

String

参数解释:

服务转发模式。

取值范围:

  • nftables:仅1.35集群及以上版本支持。替代iptables的新一代转发模式,规则管理高效、性能更优,原生支持IPv6,适配各类Service规模与集群场景,兼顾高并发短链接与大规模集群需求。

  • iptables:社区传统的kube-proxy模式,完全以iptables规则的方式来实现service负载均衡。该方式最主要的问题是在服务多的时候产生太多的iptables规则,非增量式更新会引入一定的时延,大规模情况下有明显的性能问题。

  • ipvs:主导开发并在社区获得广泛支持的kube-proxy模式,采用增量式更新,吞吐更高,速度更快,并可以保证service更新期间连接保持不断开,适用于大规模场景。

az

String

参数解释:

可用区(废弃中)。

CCE支持的可用区请参考地区和终端节点

extendParam

ClusterExtendParam object

参数解释:

集群扩展字段,可配置多可用区集群、专属CCE集群,以及将集群创建在特定的企业项目下等。

supportIstio

Boolean

参数解释:

支持Istio。

取值范围:

  • true: 支持istio

  • false: 不支持istio

enableDistMgt

Boolean

参数解释:

集群开启对分布式云支持。

取值范围:

  • true: 开启对分布式云支持

  • false: 关闭对分布式云支持

deletionProtection

Boolean

参数解释:

集群删除保护,如果开启后用户将无法删除该集群。

取值范围:

  • true: 开启集群删除保护

  • false: 关闭集群删除保护

configurationsOverride

Array of PackageConfiguration objects

参数解释:

覆盖集群默认组件配置。

当前支持的可配置组件及其参数详见配置管理

clusterOps

ClusterOps object

参数解释:

集群运维相关配置。

encryptionConfig

EncryptionConfig object

参数解释

secret资源落盘加密配置,当前仅支持配置一种加密方式。默认使用cce托管密钥(用户侧不感知该密钥)进行加密。

取值范围

不涉及

secretConfig

SecretConfig object

参数解释

secret禁用配置,控制是否在集群中禁用以Secret形式静态存储的临时凭据。

取值范围

不涉及

certificateAuthority

CertificateAuthority object

参数解释

CCE集群的证书信息

取值范围

不涉及

表15 HostNetwork

参数

参数类型

描述

vpc

String

参数解释:

用于创建节点的VPC的ID。

取值范围:

不涉及

subnet

String

参数解释:

用于创建节点的子网的网络ID。

取值范围:

不涉及

SecurityGroup

String

参数解释:

集群默认的Node节点安全组ID。

取值范围:

不涉及

controlPlaneSecurityGroup

String

参数解释:

集群控制面节点安全组ID。

取值范围:

不涉及

autoGenerateSecurityGroupHardeningConfig

AutoGenerateSecurityGroupHardeningConfigSpec object

参数解释:

自动创建安全组时的安全加固策略。

取值范围:

不涉及

表16 AutoGenerateSecurityGroupHardeningConfigSpec

参数

参数类型

描述

portsToDisable

Array of strings

参数解释:

自动创建安全组时可选择不开放node节点相关端口,支持单端口和端口段两种形式。示例如下:

"portsToDisable": ["22", "4090-4099"]

取值范围:

端口号仅支持整数,范围[1-65535]

表17 ContainerNetwork

参数

参数类型

描述

mode

String

参数解释:

容器网络类型。

取值范围:

  • overlay_l2:容器隧道网络,通过OVS(OpenVSwitch)为容器构建的overlay_l2网络。

  • vpc-router:VPC网络,使用ipvlan和自定义VPC路由为容器构建的Underlay的l2网络。

  • eni:云原生网络2.0,深度整合VPC原生ENI弹性网卡能力,采用VPC网段分配容器地址,支持ELB直通容器,享有高性能,创建CCE Turbo集群时指定。

cidr

String

参数解释:

容器网络网段,建议使用网段10.0.0.0/12~19,172.16.0.0/16~19,192.168.0.0/16~19,如存在网段冲突,将会报错。

取值范围:

满足IPv4 CIDR格式

cidrs

Array of ContainerCIDR objects

参数解释:

容器网络网段列表。1.21及新版本集群使用cidrs字段,当集群网络类型为vpc-router类型时,支持多个容器网段,最多配置20个;1.21之前版本若使用cidrs字段,则取值cidrs数组中的第一个cidr元素作为容器网络网段地址。

enableContainerCIDRsReservation

Boolean

参数解释

VPC容器网段预留。在VPC的默认路由表中添加容器网段路由,避免创建与容器网段冲突的子网。支持的集群版本如下:

  • v1.28.15-r70及以上版本

  • v1.29.15-r30及以上版本

  • v1.30.14-r30及以上版本

  • v1.31.10-r30及以上版本

  • v1.32.6-r30及以上版本

  • v1.33.5-r20及以上版本

取值范围

  • false:不开启VPC容器网段预留

  • true:开启VPC容器网段预留

表18 ContainerCIDR

参数

参数类型

描述

cidr

String

参数解释:

容器网络网段,建议使用网段10.0.0.0/12~19,172.16.0.0/16~19,192.168.0.0/16~19。

取值范围:

不涉及

表19 EniNetwork

参数

参数类型

描述

eniSubnetId

String

参数解释:

ENI所在子网的IPv4子网ID。

取值范围:

不涉及

eniSubnetCIDR

String

参数解释:

ENI子网CIDR。

取值范围:

不涉及

subnets

Array of NetworkSubnet objects

参数解释:

IPv4子网ID列表。

表20 NetworkSubnet

参数

参数类型

描述

subnetID

String

参数解释:

用于创建容器网卡的子网的IPv4子网ID。

取值范围:

不涉及

表21 ServiceNetwork

参数

参数类型

描述

IPv4CIDR

String

参数解释:

kubernetes clusterIP IPv4 CIDR取值范围。

取值范围:

不涉及

IPv6CIDR

String

参数解释:

kubernetes clusterIP IPv6 CIDR取值范围。

取值范围:

不涉及

表22 PublicAccess

参数

参数类型

描述

cidrs

Array of strings

参数解释:

允许访问集群API的白名单网段列表,建议对VPC网段、容器网段放通。

取值范围:

不涉及

表23 Authentication

参数

参数类型

描述

mode

String

参数解释:

集群认证模式。

取值范围:

  • kubernetes 1.11及之前版本的集群支持“x509”、“rbac”和“authenticating_proxy”,默认取值为“x509”。

  • kubernetes 1.13版本的集群支持“rbac”和“authenticating_proxy”,默认取值为“rbac”。

  • kubernetes 1.15及以上版本的集群支持“x509”、“rbac”和“authenticating_proxy”,默认取值为“rbac”。

authenticatingProxy

AuthenticatingProxy object

参数解释:

authenticatingProxy模式相关配置。

表24 AuthenticatingProxy

参数

参数类型

描述

ca

String

参数解释:

authenticating_proxy模式配置的x509格式CA证书(base64编码)。

取值范围:

最大长度:1M。

cert

String

参数解释:

authenticating_proxy模式配置的x509格式CA证书签发的客户端证书,用于kube-apiserver到扩展apiserver的认证。(base64编码)。

取值范围:

最大长度:1M。

privateKey

String

参数解释:

authenticating_proxy模式配置的x509格式CA证书签发的客户端证书时对应的私钥,用于kube-apiserver到扩展apiserver的认证。Kubernetes集群使用的私钥尚不支持密码加密,请使用未加密的私钥。(base64编码)。

取值范围:

最大长度:1M。

表25 MasterSpec

参数

参数类型

描述

availabilityZone

String

参数解释:

控制节点所在的可用区,需要指定可用区(AZ)的名称。

CCE支持的可用区请参考地区和终端节点

取值范围:

不涉及

表26 ResourceTag

参数

参数类型

描述

key

String

参数解释:

Key值。

取值范围:

  • 不能为空且首尾不能包含空格,最多支持128个字符

  • 可用UTF-8格式表示的任意语种字母、数字和空格

  • 支持部分特殊字符:_.:=+-@

  • 不能以"_sys_"开头

value

String

参数解释:

Value值。

取值范围:

  • 可以为空但不能缺省,最多支持255个字符

  • 可用UTF-8格式表示的汉字、字母、数字和空格

  • 支持部分特殊字符:_.:/=+-@

表27 ClusterExtendParam

参数

参数类型

描述

clusterAZ

String

参数解释:

集群控制节点可用区配置。

CCE支持的可用区请参考地区和终端节点

取值范围:

  • 指定局点支持可用区。

  • multi_az:多可用区,可选。仅使用多控制节点集群时才可以配置多可用区。

  • 专属云计算池可用区:用于指定专属云可用区部署集群控制节点。如果需配置专属CCE集群,该字段为必选。

dssMasterVolumes

String

参数解释:

用于指定控制节点的系统盘和数据盘使用专属分布式存储,未指定或者值为空时,默认使用EVS云硬盘。

取值范围:

不涉及

enterpriseProjectId

String

参数解释:

集群所属的企业项目ID。

取值范围:

不涉及

kubeProxyMode

String

参数解释:

服务转发模式,支持以下两种实现:

取值范围:

  • nftables:仅1.35集群及以上版本支持。替代iptables的新一代转发模式,规则管理高效、性能更优,原生支持IPv6,适配各类Service规模与集群场景,兼顾高并发短链接与大规模集群需求。

  • iptables:社区传统的kube-proxy模式,完全以iptables规则的方式来实现service负载均衡。该方式最主要的问题是在服务多的时候产生太多的iptables规则,非增量式更新会引入一定的时延,大规模情况下有明显的性能问题

  • ipvs:主导开发并在社区获得广泛支持的kube-proxy模式,采用增量式更新,吞吐更高,速度更快,并可以保证service更新期间连接保持不断开,适用于大规模场景。

clusterExternalIP

String

参数解释:

集群控制节点弹性公网IP,绑定后可以通过该弹性公网IP访问集群管控面API。

取值范围:

不涉及

alpha.cce/fixPoolMask

String

参数解释:

容器网络固定IP池掩码位数,该参数决定节点可分配容器IP数量,与创建节点时设置的maxPods参数共同决定节点最多可以创建多少个Pod,

具体请参见节点可创建的最大Pod数量说明

取值范围:

整数字符串取值范围: 24 ~ 28

decMasterFlavor

String

参数解释:

专属CCE集群指定可控制节点的规格。

取值范围:

不涉及

dockerUmaskMode

String

参数解释:

集群默认Docker的UmaskMode配置。

取值范围:

  • secure

  • normal

kubernetes.io/cpuManagerPolicy

String

参数解释:

集群CPU管理策略。

取值范围:

  • none(或空值):关闭工作负载实例独占CPU核的功能,优点是CPU共享池的可分配核数较多

  • static:支持给节点上的工作负载实例配置CPU独占,适用于对CPU缓存和调度延迟敏感的工作负载,Turbo集群下仅对普通容器节点有效,安全容器节点无效。

orderID

String

参数解释:

订单ID。

取值范围:

不涉及

periodType

String

参数解释:

订购周期单位。

取值范围:

  • month:月

  • year:年

periodNum

Integer

参数解释:

订购周期数

取值范围:

  • periodType=month(周期类型为月)时,取值为[1-9]。

  • periodType=year(周期类型为年)时,取值为[1-3]。

isAutoRenew

String

参数解释:

是否自动续订

取值范围:

  • "true":自动续订

  • "false":不自动续订

isAutoPay

String

参数解释:

是否自动扣款。

取值范围:

  • "true":自动扣款

  • "false":不自动扣款

upgradefrom

String

参数解释:

记录集群通过何种升级方式升级到当前版本。

取值范围:

不涉及

表28 PackageConfiguration

参数

参数类型

描述

name

String

参数解释:

组件名称。

取值范围:

不涉及

configurations

Array of ConfigurationItem objects

参数解释:

组件配置项。

表29 ConfigurationItem

参数

参数类型

描述

name

String

参数解释:

组件配置参数名称。

当前集群支持的可配置组件及其参数详见修改CCE集群配置,当前节点池支持的可配置组件及其参数详见修改节点池配置

取值范围:

不涉及

value

Object

参数解释:

组件配置参数值。

当前集群支持的可配置组件及其参数详见修改CCE集群配置,当前节点池支持的可配置组件及其参数详见修改节点池配置

取值范围:

不涉及

表30 ClusterOps

参数

参数类型

描述

alarm

AlarmInfo object

参数解释:

告警助手参数配置。基于AOM服务的告警能力实现,提供集群内的告警快速检索、告警快速配置的能力,告警中心的指标类告警规则依赖云原生监控插件上报数据到AOM实例。

表31 AlarmInfo

参数

参数类型

描述

topics

Array of strings

参数解释:

联系组列表。填写SMN主题名称,通过配置告警联系组,分组管理订阅终端,接收告警信息。

alarmRuleTemplateId

String

参数解释:

开启告警助手时传入告警模板ID。默认采用容器场景下的告警规则模板。

取值范围:

不涉及

promInstanceID

String

参数解释:

开启告警助手时传入AOM普罗实例的id。若未安装普罗插件或者未对接AOM实例,此参数无需指定,告警中心将不会创建指标类告警规则。

取值范围:

不涉及

promEnterpriseProjectID

String

参数解释:

开启告警助手时传入AOM普罗实例的企业项目id。若未安装普罗插件或者未对接AOM实例,此参数无需指定,告警中心将不会创建指标类告警规则。

取值范围:

不涉及

表32 EncryptionConfig

参数

参数类型

描述

mode

String

参数解释

加密模式,可以配置为使用cce本地密钥加密或KMS加密。

取值范围

  • Default:使用cce本地密钥加密

  • KMS:使用KMS加密模式

kmsKeyID

String

参数解释

kms密钥ID

  • 集群创建API中,如果mode字段设置为Default,无需填写该字段;如果mode字段设置为KMS,则支持填写该字段。若字段为空,则默认使用KMS默认密钥进行填充,默认密钥不存在时云服务将自动为用户创建cce/default默认密钥。 用户需使用真实存在的KMS密钥,并且在集群生命周期结束前,禁止删除、禁用密钥等操作,防止集群功能异常(集群设置该密钥后不允许修改)。

  • 集群查询API中,如果mode字段设置为Default,则该字段返回为空;若mode字段设置为KMS,则该字段为具体的密钥ID。

取值范围

不涉及

表33 SecretConfig

参数

参数类型

描述

disableDefaultAddonCredSecret

Boolean

参数解释:

是否在集群中禁用默认插件凭证(paas.elb、paas.aksk secret)。该Secret的data内容是临时AK/SK数据,部分插件在未配置自定义委托时会使用它作为IAM凭证访问其他云服务。

更多信息请参见禁用集群中静态存储的临时凭据说明

取值范围:

  • true: 禁用

  • false: 启用

disableNodeAgencyCredSecret

Boolean

参数解释:

是否在集群中禁用节点凭证(node-agency-cred secret)。该Secret的data内容是临时AK/SK数据,节点上安装的系统组件默认使用该凭证。

更多信息请参见禁用集群中静态存储的临时凭据说明

取值范围:

  • true: 禁用

  • false: 启用

disableDefaultImagePullSecret

Boolean

参数解释:

是否在集群中禁用默认镜像访问凭证(default-secret secret)。该Secret的data内容是SWR临时登录指令,用于SWR的私有镜像拉取。

更多信息请参见禁用集群中静态存储的临时凭据说明

取值范围:

  • true: 禁用

  • false: 启用

表34 CertificateAuthority

参数

参数类型

描述

data

String

参数解释:

Base64编码的CCE集群根证书

取值范围:

不涉及

表35 ClusterStatus

参数

参数类型

描述

phase

String

参数解释:

集群状态。

取值范围:

  • Available:可用,表示集群处于正常状态。

  • Unavailable:不可用,表示集群异常,需手动删除。

  • ScalingUp:扩容中,表示集群正处于扩容过程中。

  • ScalingDown:缩容中,表示集群正处于缩容过程中。

  • Creating:创建中,表示集群正处于创建过程中。

  • Deleting:删除中,表示集群正处于删除过程中。

  • Upgrading:升级中,表示集群正处于升级过程中。

  • Resizing:规格变更中,表示集群正处于变更规格中。

  • ResizeFailed:规格变更异常,表示集群变更规格异常。

  • RollingBack:回滚中,表示集群正处于回滚过程中。

  • RollbackFailed:回滚异常,表示集群回滚异常。

  • Hibernating:休眠中,表示集群正处于休眠过程中。

  • Hibernation:已休眠,表示集群正处于休眠状态。

  • Freezing:冻结中,表示集群正处于冻结过程中。

  • Frozen:已冻结,表示集群正处于冻结状态。

  • UnFreezing:解冻中,表示集群正处于解冻过程中。

  • Awaking:唤醒中,表示集群正处于从休眠状态唤醒的过程中。

  • Empty:集群无任何资源(已废弃)

  • Error:错误,表示集群资源异常,可尝试手动删除。

jobID

String

参数解释:

任务ID,集群当前状态关联的任务ID。当前支持:

  • 创建集群时返回关联的任务ID,可通过任务ID查询创建集群的附属任务信息;

  • 删除集群或者删除集群失败时返回关联的任务ID,此字段非空时,可通过任务ID查询删除集群的附属任务信息。

取值范围:

不涉及

说明:
任务信息具有一定时效性,仅用于短期跟踪任务进度,请勿用于集群状态判断等额外场景。

reason

String

参数解释:

集群变为当前状态的原因,在集群在非“Available”状态下时,会返回此参数。

取值范围:

不涉及

message

String

参数解释:

集群变为当前状态的原因的详细信息,在集群在非“Available”状态下时,会返回此参数。

取值范围:

不涉及

endpoints

Array of ClusterEndpoints objects

参数解释:

集群中 kube-apiserver 的访问地址。

isLocked

Boolean

参数解释:

CBC资源锁定

取值范围:

  • true: 是CBC锁定资源

  • false: 非CBC锁定资源

lockScene

String

参数解释:

CBC资源锁定场景

取值范围:

不涉及

lockSource

String

参数解释:

锁定资源

取值范围:

不涉及

lockSourceId

String

参数解释:

锁定的资源ID

取值范围:

不涉及

deleteOption

Object

参数解释:

删除配置状态(仅删除请求响应包含)

取值范围:

不涉及

deleteStatus

Object

参数解释:

删除状态信息(仅删除请求响应包含)

取值范围:

不涉及

conditions

Array of ClusterCondition objects

参数解释

集群当前详细状态列表,详情参见Condition类型定义。

表36 ClusterEndpoints

参数

参数类型

描述

url

String

参数解释:

集群中 kube-apiserver 的访问地址。

取值范围:

不涉及

type

String

参数解释:

集群访问地址的类型。

取值范围:

  • Internal:用户子网内访问的地址

  • External:公网访问的地址

表37 ClusterCondition

参数

参数类型

描述

type

String

参数解释

状态类型。

取值范围

  • "AgencyAvailable": CCE集群自定义委托的状态。

  • "ClusterCertificate": CCE集群证书的状态。

  • "ClusterCustomCertificate": CCE集群自有证书的状态。

  • "CertificateRotation": CCE集群证书更新的状态。

  • "CustomCertificateRotation": CCE集群自有证书更新的状态。

  • "OpenIDConnectProcessing": CCE集群开启OIDC特性处理中状态。

  • "OpenIDConnectProcessSuccess": CCE集群开启OIDC特性成功状态。

  • "OpenIDConnectProcessFailed": CCE集群开启OIDC特性失败状态。

status

String

参数解释

Condition当前状态。

取值范围

  • "True"

  • "False"

lastProbeTime

String

参数解释

上次状态检查时间。

取值范围

不涉及

lastTransitTime

String

参数解释

上次状态变更时间。

取值范围

不涉及

reason

String

参数解释

上次状态变更原因。

取值范围

  • type为ClusterCertificate、ClusterCustomCertificate时取值范围:

    • CertificateValid:证书状态正常

    • CertificateExpiringWithin180Days:证书有效期低于180天

    • CertificateExpiringWithin30Days:证书有效期低于30天

    • CertificateExpired:证书已过期

  • type为CertificateRotation、CustomCertificateRotation时取值范围:

    • RotationInProgress:更新中

    • RotationSucceeded:更新成功

    • RotationFailed:更新失败

message

String

参数解释

Condition详细描述。

取值范围

不涉及

请求示例

  • 仅更新集群描述

    {
      "spec" : {
        "description" : "new description"
      }
    }
  • 仅更新集群自定义证书SAN

    {
      "spec" : {
        "customSan" : [ "192.168.1.0", "example.com" ]
      }
    }
  • 同时更新集群描述和自定义证书SAN

    {
      "spec" : {
        "description" : "new description",
        "customSan" : [ "192.168.1.0", "example.com" ]
      }
    }
  • 添加集群容器网段(v1.21版本以上VPC网络模型的集群适用)

    {
      "spec" : {
        "containerNetwork" : {
          "cidrs" : [ {
            "cidr" : "10.10.0.0/16"
          }, {
            "cidr" : "10.11.0.0/16"
          } ]
        }
      }
    }
  • 修改集群默认节点安全组

    /api/v3/projects/{project_id}/clusters/{cluster_id}
    
    {
      "spec" : {
        "hostNetwork" : {
          "SecurityGroup" : "6ee29825-8f49-4796-b33a-fc76f84a59ae"
        }
      }
    }

响应示例

状态码:200

表示更新指定集群成功。

{
  "kind" : "Cluster",
  "apiVersion" : "v3",
  "metadata" : {
    "alias" : "mycluster",
    "name" : "mycluster",
    "uid" : "4d1ecb2c-229a-11e8-9c75-0255ac100ceb",
    "creationTimestamp" : "2018-08-02 03:48:58.968214406 +0000 UTC",
    "updateTimestamp" : "2018-08-02 06:39:36.844676088 +0000 UTC"
  },
  "spec" : {
    "type" : "VirtualMachine",
    "flavor" : "cce.s1.small",
    "version" : "v1.7.3-r13",
    "description" : "new description",
    "customSan" : [ "192.168.1.0", "example.com" ],
    "hostNetwork" : {
      "vpc" : "4d1ecb2c-229a-11e8-9c75-0255ac100ceb",
      "subnet" : "4d1ecb2c-229a-11e8-9c75-0255ac100ceb",
      "SecurityGroup" : "6ee29825-8f49-4796-b33a-fc76f84a59ae"
    },
    "containerNetwork" : {
      "mode" : "overlay_l2",
      "cidr" : "172.17.0.0/16"
    },
    "authentication" : {
      "mode" : "x509",
      "authenticatingProxy" : { }
    },
    "billingMode" : 0
  },
  "status" : {
    "phase" : "Available",
    "endpoints" : [ {
      "url" : "https://192.168.0.11:5443",
      "type" : "Internal"
    } ]
  }
}

SDK代码示例

SDK代码示例如下。

  • 仅更新集群描述

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.cce.v3.region.CceRegion;
    import com.huaweicloud.sdk.cce.v3.*;
    import com.huaweicloud.sdk.cce.v3.model.*;
    
    
    public class UpdateClusterSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
    
            CceClient client = CceClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(CceRegion.valueOf("<YOUR REGION>"))
                    .build();
            UpdateClusterRequest request = new UpdateClusterRequest();
            request.withClusterId("{cluster_id}");
            ClusterInformation body = new ClusterInformation();
            ClusterInformationSpec specbody = new ClusterInformationSpec();
            specbody.withDescription("new description");
            body.withSpec(specbody);
            request.withBody(body);
            try {
                UpdateClusterResponse response = client.updateCluster(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 仅更新集群自定义证书SAN

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.cce.v3.region.CceRegion;
    import com.huaweicloud.sdk.cce.v3.*;
    import com.huaweicloud.sdk.cce.v3.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class UpdateClusterSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
    
            CceClient client = CceClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(CceRegion.valueOf("<YOUR REGION>"))
                    .build();
            UpdateClusterRequest request = new UpdateClusterRequest();
            request.withClusterId("{cluster_id}");
            ClusterInformation body = new ClusterInformation();
            List<String> listSpecCustomSan = new ArrayList<>();
            listSpecCustomSan.add("192.168.1.0");
            listSpecCustomSan.add("example.com");
            ClusterInformationSpec specbody = new ClusterInformationSpec();
            specbody.withCustomSan(listSpecCustomSan);
            body.withSpec(specbody);
            request.withBody(body);
            try {
                UpdateClusterResponse response = client.updateCluster(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 同时更新集群描述和自定义证书SAN

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.cce.v3.region.CceRegion;
    import com.huaweicloud.sdk.cce.v3.*;
    import com.huaweicloud.sdk.cce.v3.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class UpdateClusterSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
    
            CceClient client = CceClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(CceRegion.valueOf("<YOUR REGION>"))
                    .build();
            UpdateClusterRequest request = new UpdateClusterRequest();
            request.withClusterId("{cluster_id}");
            ClusterInformation body = new ClusterInformation();
            List<String> listSpecCustomSan = new ArrayList<>();
            listSpecCustomSan.add("192.168.1.0");
            listSpecCustomSan.add("example.com");
            ClusterInformationSpec specbody = new ClusterInformationSpec();
            specbody.withDescription("new description")
                .withCustomSan(listSpecCustomSan);
            body.withSpec(specbody);
            request.withBody(body);
            try {
                UpdateClusterResponse response = client.updateCluster(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 添加集群容器网段(v1.21版本以上VPC网络模型的集群适用)

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.cce.v3.region.CceRegion;
    import com.huaweicloud.sdk.cce.v3.*;
    import com.huaweicloud.sdk.cce.v3.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class UpdateClusterSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
    
            CceClient client = CceClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(CceRegion.valueOf("<YOUR REGION>"))
                    .build();
            UpdateClusterRequest request = new UpdateClusterRequest();
            request.withClusterId("{cluster_id}");
            ClusterInformation body = new ClusterInformation();
            List<ContainerCIDR> listContainerNetworkCidrs = new ArrayList<>();
            listContainerNetworkCidrs.add(
                new ContainerCIDR()
                    .withCidr("10.10.0.0/16")
            );
            listContainerNetworkCidrs.add(
                new ContainerCIDR()
                    .withCidr("10.11.0.0/16")
            );
            ContainerNetworkUpdate containerNetworkSpec = new ContainerNetworkUpdate();
            containerNetworkSpec.withCidrs(listContainerNetworkCidrs);
            ClusterInformationSpec specbody = new ClusterInformationSpec();
            specbody.withContainerNetwork(containerNetworkSpec);
            body.withSpec(specbody);
            request.withBody(body);
            try {
                UpdateClusterResponse response = client.updateCluster(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 修改集群默认节点安全组

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.cce.v3.region.CceRegion;
    import com.huaweicloud.sdk.cce.v3.*;
    import com.huaweicloud.sdk.cce.v3.model.*;
    
    
    public class UpdateClusterSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
    
            CceClient client = CceClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(CceRegion.valueOf("<YOUR REGION>"))
                    .build();
            UpdateClusterRequest request = new UpdateClusterRequest();
            request.withClusterId("{cluster_id}");
            ClusterInformation body = new ClusterInformation();
            ClusterInformationSpecHostNetwork hostNetworkSpec = new ClusterInformationSpecHostNetwork();
            hostNetworkSpec.withSecurityGroup("6ee29825-8f49-4796-b33a-fc76f84a59ae");
            ClusterInformationSpec specbody = new ClusterInformationSpec();
            specbody.withHostNetwork(hostNetworkSpec);
            body.withSpec(specbody);
            request.withBody(body);
            try {
                UpdateClusterResponse response = client.updateCluster(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 仅更新集群描述

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkcce.v3.region.cce_region import CceRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkcce.v3 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        client = CceClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(CceRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = UpdateClusterRequest()
            request.cluster_id = "{cluster_id}"
            specbody = ClusterInformationSpec(
                description="new description"
            )
            request.body = ClusterInformation(
                spec=specbody
            )
            response = client.update_cluster(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 仅更新集群自定义证书SAN

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkcce.v3.region.cce_region import CceRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkcce.v3 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        client = CceClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(CceRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = UpdateClusterRequest()
            request.cluster_id = "{cluster_id}"
            listCustomSanSpec = [
                "192.168.1.0",
                "example.com"
            ]
            specbody = ClusterInformationSpec(
                custom_san=listCustomSanSpec
            )
            request.body = ClusterInformation(
                spec=specbody
            )
            response = client.update_cluster(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 同时更新集群描述和自定义证书SAN

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkcce.v3.region.cce_region import CceRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkcce.v3 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        client = CceClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(CceRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = UpdateClusterRequest()
            request.cluster_id = "{cluster_id}"
            listCustomSanSpec = [
                "192.168.1.0",
                "example.com"
            ]
            specbody = ClusterInformationSpec(
                description="new description",
                custom_san=listCustomSanSpec
            )
            request.body = ClusterInformation(
                spec=specbody
            )
            response = client.update_cluster(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 添加集群容器网段(v1.21版本以上VPC网络模型的集群适用)

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkcce.v3.region.cce_region import CceRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkcce.v3 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        client = CceClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(CceRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = UpdateClusterRequest()
            request.cluster_id = "{cluster_id}"
            listCidrsContainerNetwork = [
                ContainerCIDR(
                    cidr="10.10.0.0/16"
                ),
                ContainerCIDR(
                    cidr="10.11.0.0/16"
                )
            ]
            containerNetworkSpec = ContainerNetworkUpdate(
                cidrs=listCidrsContainerNetwork
            )
            specbody = ClusterInformationSpec(
                container_network=containerNetworkSpec
            )
            request.body = ClusterInformation(
                spec=specbody
            )
            response = client.update_cluster(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 修改集群默认节点安全组

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkcce.v3.region.cce_region import CceRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkcce.v3 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        client = CceClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(CceRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = UpdateClusterRequest()
            request.cluster_id = "{cluster_id}"
            hostNetworkSpec = ClusterInformationSpecHostNetwork(
                security_group="6ee29825-8f49-4796-b33a-fc76f84a59ae"
            )
            specbody = ClusterInformationSpec(
                host_network=hostNetworkSpec
            )
            request.body = ClusterInformation(
                spec=specbody
            )
            response = client.update_cluster(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 仅更新集群描述

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        cce "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
        projectId := "{project_id}"
    
        auth, err := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            SafeBuild()
    
        if err != nil {
            fmt.Println(err)
            return
        }
    
        hcClient, err := cce.CceClientBuilder().
             WithRegion(region.ValueOf("<YOUR REGION>")).
             WithCredential(auth).
             SafeBuild()
    
    
        if err != nil {
            fmt.Println(err)
            return
        }
    
        client := cce.NewCceClient(hcClient)
    
        request := &model.UpdateClusterRequest{}
    	request.ClusterId = "{cluster_id}"
    	descriptionSpec:= "new description"
    	specbody := &model.ClusterInformationSpec{
    		Description: &descriptionSpec,
    	}
    	request.Body = &model.ClusterInformation{
    		Spec: specbody,
    	}
    	response, err := client.UpdateCluster(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 仅更新集群自定义证书SAN

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        cce "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
        projectId := "{project_id}"
    
        auth, err := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            SafeBuild()
    
        if err != nil {
            fmt.Println(err)
            return
        }
    
        hcClient, err := cce.CceClientBuilder().
             WithRegion(region.ValueOf("<YOUR REGION>")).
             WithCredential(auth).
             SafeBuild()
    
    
        if err != nil {
            fmt.Println(err)
            return
        }
    
        client := cce.NewCceClient(hcClient)
    
        request := &model.UpdateClusterRequest{}
    	request.ClusterId = "{cluster_id}"
    	var listCustomSanSpec = []string{
            "192.168.1.0",
    	    "example.com",
        }
    	specbody := &model.ClusterInformationSpec{
    		CustomSan: &listCustomSanSpec,
    	}
    	request.Body = &model.ClusterInformation{
    		Spec: specbody,
    	}
    	response, err := client.UpdateCluster(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 同时更新集群描述和自定义证书SAN

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        cce "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
        projectId := "{project_id}"
    
        auth, err := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            SafeBuild()
    
        if err != nil {
            fmt.Println(err)
            return
        }
    
        hcClient, err := cce.CceClientBuilder().
             WithRegion(region.ValueOf("<YOUR REGION>")).
             WithCredential(auth).
             SafeBuild()
    
    
        if err != nil {
            fmt.Println(err)
            return
        }
    
        client := cce.NewCceClient(hcClient)
    
        request := &model.UpdateClusterRequest{}
    	request.ClusterId = "{cluster_id}"
    	var listCustomSanSpec = []string{
            "192.168.1.0",
    	    "example.com",
        }
    	descriptionSpec:= "new description"
    	specbody := &model.ClusterInformationSpec{
    		Description: &descriptionSpec,
    		CustomSan: &listCustomSanSpec,
    	}
    	request.Body = &model.ClusterInformation{
    		Spec: specbody,
    	}
    	response, err := client.UpdateCluster(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 添加集群容器网段(v1.21版本以上VPC网络模型的集群适用)

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        cce "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
        projectId := "{project_id}"
    
        auth, err := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            SafeBuild()
    
        if err != nil {
            fmt.Println(err)
            return
        }
    
        hcClient, err := cce.CceClientBuilder().
             WithRegion(region.ValueOf("<YOUR REGION>")).
             WithCredential(auth).
             SafeBuild()
    
    
        if err != nil {
            fmt.Println(err)
            return
        }
    
        client := cce.NewCceClient(hcClient)
    
        request := &model.UpdateClusterRequest{}
    	request.ClusterId = "{cluster_id}"
    	var listCidrsContainerNetwork = []model.ContainerCidr{
            {
                Cidr: "10.10.0.0/16",
            },
            {
                Cidr: "10.11.0.0/16",
            },
        }
    	containerNetworkSpec := &model.ContainerNetworkUpdate{
    		Cidrs: &listCidrsContainerNetwork,
    	}
    	specbody := &model.ClusterInformationSpec{
    		ContainerNetwork: containerNetworkSpec,
    	}
    	request.Body = &model.ClusterInformation{
    		Spec: specbody,
    	}
    	response, err := client.UpdateCluster(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 修改集群默认节点安全组

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        cce "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
        projectId := "{project_id}"
    
        auth, err := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            SafeBuild()
    
        if err != nil {
            fmt.Println(err)
            return
        }
    
        hcClient, err := cce.CceClientBuilder().
             WithRegion(region.ValueOf("<YOUR REGION>")).
             WithCredential(auth).
             SafeBuild()
    
    
        if err != nil {
            fmt.Println(err)
            return
        }
    
        client := cce.NewCceClient(hcClient)
    
        request := &model.UpdateClusterRequest{}
    	request.ClusterId = "{cluster_id}"
    	securityGroupHostNetwork:= "6ee29825-8f49-4796-b33a-fc76f84a59ae"
    	hostNetworkSpec := &model.ClusterInformationSpecHostNetwork{
    		SecurityGroup: &securityGroupHostNetwork,
    	}
    	specbody := &model.ClusterInformationSpec{
    		HostNetwork: hostNetworkSpec,
    	}
    	request.Body = &model.ClusterInformation{
    		Spec: specbody,
    	}
    	response, err := client.UpdateCluster(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

表示更新指定集群成功。

错误码

请参见错误码

相关文档