功能介紹
該API用于更新指定的集群。

集群管理的URL格式為:https://Endpoint/uri。其中uri為資源路徑,也即API訪問的路徑。
調(diào)用方法
請參見如何調(diào)用API。
URI
PUT /api/v3/projects/{project_id}/clusters/{cluster_id}
參數(shù) |
是否必選 |
參數(shù)類型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
項目ID,獲取方式請參見如何獲取接口URI中參數(shù)。 |
cluster_id |
是 |
String |
集群ID,獲取方式請參見如何獲取接口URI中參數(shù)。 |
請求參數(shù)
參數(shù) |
是否必選 |
參數(shù)類型 |
描述 |
---|---|---|---|
Content-Type |
是 |
String |
消息體的類型(格式) |
X-Auth-Token |
是 |
String |
調(diào)用接口的認證方式分為Token和AK/SK兩種,如果您使用的Token方式,此參數(shù)為必填,請?zhí)顚慣oken的值,獲取方式請參見獲取token。 |
參數(shù) |
是否必選 |
參數(shù)類型 |
描述 |
---|---|---|---|
spec |
是 |
具體集群參數(shù) |
|
metadata |
否 |
集群基本信息,包含與名稱相關的字段 |
參數(shù) |
是否必選 |
參數(shù)類型 |
描述 |
---|---|---|---|
description |
否 |
String |
集群的描述信息。
|
customSan |
否 |
Array of strings |
集群的API Server服務端證書中的自定義SAN(Subject Alternative Name)字段,遵從SSL標準X509定義的格式規(guī)范。
示例: 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 |
否 |
容器網(wǎng)絡參數(shù),包含容器網(wǎng)段的信息。 |
|
eniNetwork |
否 |
云原生 網(wǎng)絡2.0網(wǎng)絡配置,包含CCE Turbo集群的容器子網(wǎng)信息。 |
|
hostNetwork |
否 |
節(jié)點網(wǎng)絡參數(shù),包含了Node節(jié)點默認安群組設置 |
參數(shù) |
是否必選 |
參數(shù)類型 |
描述 |
---|---|---|---|
cidrs |
否 |
容器網(wǎng)絡網(wǎng)段列表。1.21及新版本集群,當集群網(wǎng)絡類型為vpc-router時,支持增量添加容器網(wǎng)段。 此參數(shù)在集群更新后不可更改,請謹慎選擇。 |
參數(shù) |
是否必選 |
參數(shù)類型 |
描述 |
---|---|---|---|
cidr |
是 |
String |
容器網(wǎng)絡網(wǎng)段,建議使用網(wǎng)段10.0.0.0/12~19,172.16.0.0/16~19,192.168.0.0/16~19。 |
參數(shù) |
是否必選 |
參數(shù)類型 |
描述 |
---|---|---|---|
subnets |
否 |
IPv4子網(wǎng)ID列表。1.19.10及以上版本的CCE Turbo集群支持多容器子網(wǎng),同時支持增量更新容器子網(wǎng)列表。 只允許新增子網(wǎng),不可刪除已有子網(wǎng),請謹慎選擇。 請求體中需包含所有已經(jīng)存在的subnet。 |
參數(shù) |
是否必選 |
參數(shù)類型 |
描述 |
---|---|---|---|
subnetID |
是 |
String |
用于創(chuàng)建控制節(jié)點的subnet的IPv4子網(wǎng)ID(暫不支持IPv6)。獲取方法如下:
|
參數(shù) |
是否必選 |
參數(shù)類型 |
描述 |
---|---|---|---|
SecurityGroup |
否 |
String |
集群默認Node節(jié)點安全組需要放通部分端口來保證正常通信,詳細設置請參考集群安全組規(guī)則配置。 修改后的安全組只作用于新創(chuàng)建的節(jié)點和新納管的節(jié)點,存量節(jié)點的安全組需手動修改。 |
響應參數(shù)
狀態(tài)碼: 200
參數(shù) |
參數(shù)類型 |
描述 |
---|---|---|
kind |
String |
API類型,固定值“Cluster”或“cluster”,該值不可修改。 |
apiVersion |
String |
API版本,固定值“v3”,該值不可修改。 |
metadata |
集群的基本信息,為集合類的元素類型,包含一組由不同名稱定義的屬性。 |
|
spec |
spec是集合類的元素類型,您對需要管理的集群對象進行詳細描述的主體部分都在spec中給出。CCE通過spec的描述來創(chuàng)建或更新對象。 |
|
status |
集合類的元素類型,用于記錄對象在系統(tǒng)中的當前狀態(tài)信息,包含了集群狀態(tài)和本次創(chuàng)建集群作業(yè)的jobID |
參數(shù) |
參數(shù)類型 |
描述 |
---|---|---|
name |
String |
集群名稱。 命名規(guī)則:以小寫字母開頭,由小寫字母、數(shù)字、中劃線(-)組成,長度范圍4-128位,且不能以中劃線(-)結尾。 |
uid |
String |
集群ID,資源唯一標識,創(chuàng)建成功后自動生成,填寫無效。 |
alias |
String |
集群顯示名,用于在 CCE 界面顯示,該名稱創(chuàng)建后可修改。 命名規(guī)則:以小寫字母開頭,由小寫字母、數(shù)字、中劃線(-)組成,長度范圍4-128位,且不能以中劃線(-)結尾。 顯示名和其他集群的名稱、顯示名不可以重復。 在創(chuàng)建集群、更新集群請求體中,集群顯示名alias未指定或取值為空,表示與集群名稱name一致。在查詢集群等響應體中,集群顯示名alias將必然返回,未配置時將返回集群名稱name。 |
annotations |
Map<String,String> |
集群注解,由key/value組成: "annotations": {
"key1" : "value1",
"key2" : "value2"
}
說明:
|
labels |
Map<String,String> |
集群標簽,key/value對格式。 說明:
該字段值由系統(tǒng)自動生成,用于升級時前端識別集群支持的特性開關,用戶指定無效。 |
creationTimestamp |
String |
集群創(chuàng)建時間 |
updateTimestamp |
String |
集群更新時間 |
參數(shù) |
參數(shù)類型 |
描述 |
---|---|---|
category |
String |
集群類別:
|
type |
String |
集群Master節(jié)點架構:
|
flavor |
String |
字段默認值:創(chuàng)建CCE集群或鯤鵬集群時,如果是非專屬云為cce.s1.small,專屬云則為cce.dec.s1.small; 集群規(guī)格,集群創(chuàng)建完成后規(guī)格不可再變更,請按實際業(yè)務需求進行選擇:
說明:
|
version |
String |
集群版本,與Kubernetes社區(qū)基線版本保持一致,建議選擇最新版本。 在CCE控制臺支持創(chuàng)建兩種最新版本的集群??傻卿汣CE控制臺創(chuàng)建集群,在“版本”處獲取到集群版本。 其它集群版本,當前仍可通過api創(chuàng)建,但后續(xù)會逐漸下線,具體下線策略請關注CCE官方公告。 說明:
|
platformVersion |
String |
CCE集群平臺版本號,表示集群版本(version)下的內(nèi)部版本。用于跟蹤某一集群版本內(nèi)的迭代,集群版本內(nèi)唯一,跨集群版本重新計數(shù)。不支持用戶指定,集群創(chuàng)建時自動選擇對應集群版本的最新平臺版本。 platformVersion格式為:cce.X.Y
|
description |
String |
集群描述,對于集群使用目的的描述,可根據(jù)實際情況自定義,默認為空。集群創(chuàng)建成功后可通過接口更新指定的集群來做出修改,也可在CCE控制臺中對應集群的“集群詳情”下的“描述”處進行修改。僅支持utf-8編碼。 |
customSan |
Array of strings |
集群的API Server服務端證書中的自定義SAN(Subject Alternative Name)字段,遵從SSL標準X509定義的格式規(guī)范。
示例: 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
|
ipv6enable |
Boolean |
集群是否使用IPv6模式,1.15版本及以上支持。 |
hostNetwork |
節(jié)點網(wǎng)絡參數(shù),包含了 虛擬私有云VPC 和子網(wǎng)的ID信息,而VPC是集群內(nèi)節(jié)點之間的通信依賴,所以是必選的參數(shù)集。 |
|
containerNetwork |
容器網(wǎng)絡參數(shù),包含了容器網(wǎng)絡類型和容器網(wǎng)段的信息。 |
|
eniNetwork |
云原生網(wǎng)絡2.0網(wǎng)絡配置,創(chuàng)建CCE Turbo集群時指定。 |
|
serviceNetwork |
服務網(wǎng)段參數(shù),包含IPv4 CIDR。 |
|
authentication |
集群認證方式相關配置。 |
|
billingMode |
Integer |
集群的計費方式。
默認為“按需計費”。 |
masters |
控制節(jié)點的高級配置 |
|
kubernetesSvcIpRange |
String |
服務網(wǎng)段參數(shù),kubernetes clusterIP取值范圍,1.11.7版本及以上支持。創(chuàng)建集群時如若未傳參,默認為"10.247.0.0/16"。該參數(shù)廢棄中,推薦使用新字段serviceNetwork,包含IPv4服務網(wǎng)段。 |
clusterTags |
集群資源標簽 |
|
kubeProxyMode |
String |
服務轉發(fā)模式,支持以下兩種實現(xiàn):
|
az |
String |
可用區(qū)(僅查詢返回字段)。 CCE支持的可用區(qū)請參考地區(qū)和終端節(jié)點 |
extendParam |
集群擴展字段,可配置多可用區(qū)集群、專屬CCE集群,以及將集群創(chuàng)建在特定的企業(yè)項目下等。 |
|
supportIstio |
Boolean |
支持Istio |
configurationsOverride |
覆蓋集群默認組件配置 若指定了不支持的組件或組件不支持的參數(shù),該配置項將被忽略。 當前支持的可配置組件及其參數(shù)詳見 配置管理 |
參數(shù) |
參數(shù)類型 |
描述 |
---|---|---|
vpc |
String |
用于創(chuàng)建控制節(jié)點的VPC的ID。 獲取方法如下:
說明:
當前vpc-router容器網(wǎng)絡模型不支持對接含拓展網(wǎng)段的VPC。 |
subnet |
String |
用于創(chuàng)建控制節(jié)點的subnet的網(wǎng)絡ID。獲取方法如下:
|
SecurityGroup |
String |
集群默認的Node節(jié)點安全組ID,不指定該字段系統(tǒng)將自動為用戶創(chuàng)建默認Node節(jié)點安全組,指定該字段時集群將綁定指定的安全組。Node節(jié)點安全組需要放通部分端口來保證正常通信。詳細設置請參考集群安全組規(guī)則配置。 |
參數(shù) |
參數(shù)類型 |
描述 |
---|---|---|
mode |
String |
容器網(wǎng)絡類型(只可選擇其一)
|
cidr |
String |
容器網(wǎng)絡網(wǎng)段,建議使用網(wǎng)段10.0.0.0/12~19,172.16.0.0/16~19,192.168.0.0/16~19,如存在網(wǎng)段沖突,將會報錯。 此參數(shù)在集群創(chuàng)建后不可更改,請謹慎選擇。(已廢棄,如填寫cidrs將忽略該cidr) |
cidrs |
容器網(wǎng)絡網(wǎng)段列表。1.21及新版本集群使用cidrs字段,當集群網(wǎng)絡類型為vpc-router類型時,支持多個容器網(wǎng)段;1.21之前版本若使用cidrs字段,則取值cidrs數(shù)組中的第一個cidr元素作為容器網(wǎng)絡網(wǎng)段地址。 此參數(shù)在集群創(chuàng)建后不可更改,請謹慎選擇。 |
參數(shù) |
參數(shù)類型 |
描述 |
---|---|---|
cidr |
String |
容器網(wǎng)絡網(wǎng)段,建議使用網(wǎng)段10.0.0.0/12~19,172.16.0.0/16~19,192.168.0.0/16~19。 |
參數(shù) |
參數(shù)類型 |
描述 |
---|---|---|
eniSubnetId |
String |
ENI所在子網(wǎng)的IPv4子網(wǎng)ID(暫不支持IPv6,廢棄中)。獲取方法如下:
|
eniSubnetCIDR |
String |
ENI子網(wǎng)CIDR(廢棄中) |
subnets |
IPv4子網(wǎng)ID列表 |
參數(shù) |
參數(shù)類型 |
描述 |
---|---|---|
subnetID |
String |
用于創(chuàng)建控制節(jié)點的subnet的IPv4子網(wǎng)ID(暫不支持IPv6)。獲取方法如下:
|
參數(shù) |
參數(shù)類型 |
描述 |
---|---|---|
IPv4CIDR |
String |
kubernetes clusterIP IPv4 CIDR取值范圍。創(chuàng)建集群時若未傳參,默認為"10.247.0.0/16"。 |
參數(shù) |
參數(shù)類型 |
描述 |
---|---|---|
mode |
String |
集群認證模式。
|
authenticatingProxy |
authenticatingProxy模式相關配置。認證模式為authenticating_proxy時必選。 |
參數(shù) |
參數(shù)類型 |
描述 |
---|---|---|
ca |
String |
authenticating_proxy模式配置的x509格式CA證書(base64編碼)。當集群認證模式為authenticating_proxy時,此項必須填寫。 最大長度:1M |
cert |
String |
authenticating_proxy模式配置的x509格式CA證書簽發(fā)的客戶端證書,用于kube-apiserver到擴展apiserver的認證。(base64編碼)。當集群認證模式為authenticating_proxy時,此項必須填寫。 |
privateKey |
String |
authenticating_proxy模式配置的x509格式CA證書簽發(fā)的客戶端證書時對應的私鑰,用于kube-apiserver到擴展apiserver的認證。Kubernetes集群使用的私鑰尚不支持密碼加密,請使用未加密的私鑰。(base64編碼)。當集群認證模式為authenticating_proxy時,此項必須填寫。 |
參數(shù) |
參數(shù)類型 |
描述 |
---|---|---|
key |
String |
Key值。
|
value |
String |
Value值。
|
參數(shù) |
參數(shù)類型 |
描述 |
---|---|---|
clusterAZ |
String |
集群控制節(jié)點可用區(qū)配置。 CCE支持的可用區(qū)請參考地區(qū)和終端節(jié)點
|
dssMasterVolumes |
String |
用于指定控制節(jié)點的系統(tǒng)盤和數(shù)據(jù)盤使用 專屬分布式存儲 ,未指定或者值為空時,默認使用EVS 云硬盤 。 如果配置專屬CCE集群,該字段為必選,請按照如下格式設置: <rootVol.dssPoolID>.<rootVol.volType>;<dataVol.dssPoolID>.<dataVol.volType>
字段說明:
樣例:c950ee97-587c-4f24-8a74-3367e3da570f.sas;6edbc2f4-1507-44f8-ac0d-eed1d2608d38.ssd 說明:
非專屬CCE集群不支持配置該字段。 |
enterpriseProjectId |
String |
集群所屬的企業(yè)項目ID。 說明:
|
kubeProxyMode |
String |
服務轉發(fā)模式,支持以下兩種實現(xiàn):
說明:
此參數(shù)已廢棄,若同時指定此參數(shù)和ClusterSpec下的kubeProxyMode,以ClusterSpec下的為準。 |
clusterExternalIP |
String |
master 彈性公網(wǎng)IP |
alpha.cce/fixPoolMask |
String |
容器網(wǎng)絡固定IP池掩碼位數(shù),僅vpc-router網(wǎng)絡支持。 該參數(shù)決定節(jié)點可分配容器IP數(shù)量,與創(chuàng)建節(jié)點時設置的maxPods參數(shù)共同決定節(jié)點最多可以創(chuàng)建多少個Pod, 具體請參見節(jié)點最多可以創(chuàng)建多少Pod。 整數(shù)字符傳取值范圍: 24 ~ 28 |
decMasterFlavor |
String |
專屬CCE集群指定可控制節(jié)點的規(guī)格。 |
dockerUmaskMode |
String |
集群默認Docker的UmaskMode配置,可取值為secure或normal,不指定時默認為normal。 |
kubernetes.io/cpuManagerPolicy |
String |
集群CPU管理策略。取值為none(或空值)或static,默認為none(或空值)。
|
orderID |
String |
訂單ID,集群付費類型為自動付費包周期類型時,響應中會返回此字段(僅創(chuàng)建場景涉及)。 |
periodType |
String |
說明:
作為請求參數(shù),billingMode為1(包周期)時生效,且為必選。 作為響應參數(shù),僅在創(chuàng)建包周期集群時返回。 |
periodNum |
Integer |
訂購周期數(shù),取值范圍:
說明:
作為請求參數(shù),billingMode為1時生效,且為必選。 作為響應參數(shù),僅在創(chuàng)建包周期集群時返回。 |
isAutoRenew |
String |
是否自動續(xù)訂
說明:
billingMode為1時生效,不填寫此參數(shù)時默認不會自動續(xù)費。 |
isAutoPay |
String |
是否自動扣款
說明:
billingMode為1時生效,不填寫此參數(shù)時默認不會自動扣款。 |
upgradefrom |
String |
記錄集群通過何種升級方式升級到當前版本。 |
參數(shù) |
參數(shù)類型 |
描述 |
---|---|---|
phase |
String |
集群狀態(tài),取值如下
|
jobID |
String |
任務ID,集群當前狀態(tài)關聯(lián)的任務ID。當前支持:
說明:
任務信息具有一定時效性,僅用于短期跟蹤任務進度,請勿用于集群狀態(tài)判斷等額外場景。 |
reason |
String |
集群變?yōu)楫斍盃顟B(tài)的原因,在集群在非“Available”狀態(tài)下時,會返回此參數(shù)。 |
message |
String |
集群變?yōu)楫斍盃顟B(tài)的原因的詳細信息,在集群在非“Available”狀態(tài)下時,會返回此參數(shù)。 |
endpoints |
集群中 kube-apiserver 的訪問地址。 |
|
isLocked |
Boolean |
CBC資源鎖定 |
lockScene |
String |
CBC資源鎖定場景 |
lockSource |
String |
鎖定資源 |
lockSourceId |
String |
鎖定的資源ID |
deleteOption |
Object |
刪除配置狀態(tài)(僅刪除請求響應包含) |
deleteStatus |
Object |
刪除狀態(tài)信息(僅刪除請求響應包含) |
請求示例
-
僅更新集群描述
{ "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" ] } }
-
添加集群容器網(wǎng)段(v1.21版本以上VPC網(wǎng)絡模型的集群適用)
{ "spec" : { "containerNetwork" : { "cidrs" : [ { "cidr" : "10.10.0.0/16" }, { "cidr" : "10.11.0.0/16" } ] } } }
-
修改集群默認節(jié)點安全組
/api/v3/projects/{project_id}/clusters/{cluster_id} { "spec" : { "hostNetwork" : { "SecurityGroup" : "6ee29825-8f49-4796-b33a-fc76f84a59ae" } } }
響應示例
狀態(tài)碼: 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代碼示例如下。
-
僅更新集群描述
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) { String ak = "<YOUR AK>"; String sk = "<YOUR SK>"; String projectId = "<project_id>"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); CceClient client = CceClient.newBuilder() .withCredential(auth) .withRegion(CceRegion.valueOf("cn-north-4")) .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
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) { String ak = "<YOUR AK>"; String sk = "<YOUR SK>"; String projectId = "<project_id>"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); CceClient client = CceClient.newBuilder() .withCredential(auth) .withRegion(CceRegion.valueOf("cn-north-4")) .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
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) { String ak = "<YOUR AK>"; String sk = "<YOUR SK>"; String projectId = "<project_id>"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); CceClient client = CceClient.newBuilder() .withCredential(auth) .withRegion(CceRegion.valueOf("cn-north-4")) .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()); } } }
-
添加集群容器網(wǎng)段(v1.21版本以上VPC網(wǎng)絡模型的集群適用)
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) { String ak = "<YOUR AK>"; String sk = "<YOUR SK>"; String projectId = "<project_id>"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); CceClient client = CceClient.newBuilder() .withCredential(auth) .withRegion(CceRegion.valueOf("cn-north-4")) .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()); } } }
-
修改集群默認節(jié)點安全組
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) { String ak = "<YOUR AK>"; String sk = "<YOUR SK>"; String projectId = "<project_id>"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); CceClient client = CceClient.newBuilder() .withCredential(auth) .withRegion(CceRegion.valueOf("cn-north-4")) .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()); } } }
-
僅更新集群描述
# coding: utf-8 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__": ak = "<YOUR AK>" sk = "<YOUR SK>" projectId = "<project_id>" credentials = BasicCredentials(ak, sk, projectId) \ client = CceClient.new_builder() \ .with_credentials(credentials) \ .with_region(CceRegion.value_of("cn-north-4")) \ .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
# coding: utf-8 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__": ak = "<YOUR AK>" sk = "<YOUR SK>" projectId = "<project_id>" credentials = BasicCredentials(ak, sk, projectId) \ client = CceClient.new_builder() \ .with_credentials(credentials) \ .with_region(CceRegion.value_of("cn-north-4")) \ .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
# coding: utf-8 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__": ak = "<YOUR AK>" sk = "<YOUR SK>" projectId = "<project_id>" credentials = BasicCredentials(ak, sk, projectId) \ client = CceClient.new_builder() \ .with_credentials(credentials) \ .with_region(CceRegion.value_of("cn-north-4")) \ .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)
-
添加集群容器網(wǎng)段(v1.21版本以上VPC網(wǎng)絡模型的集群適用)
# coding: utf-8 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__": ak = "<YOUR AK>" sk = "<YOUR SK>" projectId = "<project_id>" credentials = BasicCredentials(ak, sk, projectId) \ client = CceClient.new_builder() \ .with_credentials(credentials) \ .with_region(CceRegion.value_of("cn-north-4")) \ .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)
-
修改集群默認節(jié)點安全組
# coding: utf-8 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__": ak = "<YOUR AK>" sk = "<YOUR SK>" projectId = "<project_id>" credentials = BasicCredentials(ak, sk, projectId) \ client = CceClient.new_builder() \ .with_credentials(credentials) \ .with_region(CceRegion.value_of("cn-north-4")) \ .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)
-
僅更新集群描述
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() { ak := "<YOUR AK>" sk := "<YOUR SK>" projectId := "<project_id>" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := cce.NewCceClient( cce.CceClientBuilder(). WithRegion(region.ValueOf("cn-north-4")). WithCredential(auth). Build()) 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
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() { ak := "<YOUR AK>" sk := "<YOUR SK>" projectId := "<project_id>" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := cce.NewCceClient( cce.CceClientBuilder(). WithRegion(region.ValueOf("cn-north-4")). WithCredential(auth). Build()) 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
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() { ak := "<YOUR AK>" sk := "<YOUR SK>" projectId := "<project_id>" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := cce.NewCceClient( cce.CceClientBuilder(). WithRegion(region.ValueOf("cn-north-4")). WithCredential(auth). Build()) 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) } }
-
添加集群容器網(wǎng)段(v1.21版本以上VPC網(wǎng)絡模型的集群適用)
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() { ak := "<YOUR AK>" sk := "<YOUR SK>" projectId := "<project_id>" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := cce.NewCceClient( cce.CceClientBuilder(). WithRegion(region.ValueOf("cn-north-4")). WithCredential(auth). Build()) 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) } }
-
修改集群默認節(jié)點安全組
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() { ak := "<YOUR AK>" sk := "<YOUR SK>" projectId := "<project_id>" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := cce.NewCceClient( cce.CceClientBuilder(). WithRegion(region.ValueOf("cn-north-4")). WithCredential(auth). Build()) 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代碼示例。
狀態(tài)碼
狀態(tài)碼 |
描述 |
---|---|
200 |
表示更新指定集群成功。 |
錯誤碼
請參見錯誤碼。