功能介绍
集群升级。
-
集群升级涉及多维度的组件升级操作,强烈建议统一通过CCE控制台执行交互式升级,降低集群升级过程的业务意外受损风险;
-
当前集群升级相关接口受限开放。
调用方法
请参见如何调用API。
URI
POST /api/v3/projects/{project_id}/clusters/{cluster_id}/operation/upgrade
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
项目ID,获取方式请参见如何获取接口URI中参数。 |
cluster_id |
是 |
String |
集群ID,获取方式请参见如何获取接口URI中参数。 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
metadata |
是 |
升级元数据 |
|
spec |
是 |
升级配置信息 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
apiVersion |
是 |
String |
api版本,默认为v3 |
kind |
是 |
String |
资源类型,默认为UpgradeTask |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
addons |
否 |
插件配置列表 |
|
nodeOrder |
否 |
节点池内节点升级顺序配置。 说明:
key表示节点池ID,默认节点池取值为"DefaultPool" |
|
nodePoolOrder |
否 |
Map<String,Integer> |
节点池升级顺序配置,key/value对格式。 说明:
key表示节点池ID,默认节点池取值为"DefaultPool" value表示对应节点池的优先级,默认值为0,优先级最低,数值越大优先级越高 |
strategy |
是 |
升级策略 |
|
targetVersion |
是 |
String |
目标集群版本,例如"v1.23" |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
addonTemplateName |
是 |
String |
插件名称 |
operation |
是 |
String |
执行动作,当前升级场景支持操作为"patch" |
version |
是 |
String |
目标插件版本号 |
values |
否 |
Object |
插件参数列表,Key:Value格式 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
nodeSelector |
是 |
节点标签选择器,选择一批节点 |
|
priority |
是 |
Integer |
该批次节点的优先级,默认值为0,优先级最低,数值越大优先级越高 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
key |
是 |
String |
标签键 |
value |
否 |
Array of strings |
标签值列表 |
operator |
是 |
String |
标签逻辑运算符 |
响应参数
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
metadata |
升级任务元数据信息 |
|
spec |
升级配置信息 |
参数 |
参数类型 |
描述 |
---|---|---|
version |
String |
当前集群版本 |
targetVersion |
String |
目标集群版本,例如"v1.23" |
targetPlatformVersion |
String |
目标集群的平台版本号,表示集群版本(version)下的内部版本,不支持用户指定。 |
strategy |
升级策略 |
|
config |
Object |
升级过程中指定的集群配置 |
请求示例
升级集群至v1.23版本,并设置节点升级步长为20。
POST /api/v3/projects/{project_id}/clusters/{cluster_id}/operation/upgrade { "metadata" : { "apiVersion" : "v3", "kind" : "UpgradeTask" }, "spec" : { "clusterUpgradeAction" : { "strategy" : { "type" : "inPlaceRollingUpdate", "inPlaceRollingUpdate" : { "userDefinedStep" : 20 } }, "targetVersion" : "v1.23" } } }
响应示例
状态码: 200
表示集群升级任务下发成功。
{ "metadata" : { "uid" : "976a33e2-f545-11ed-87af-0255ac1002c2" }, "spec" : { "clusterUpgradeAction" : { "version" : "v1.19.16-r20", "targetVersion" : "v1.23.8-r0", "targetPlatformVersion" : "cce.10", "strategy" : { "type" : "inPlaceRollingUpdate", "inPlaceRollingUpdate" : { "userDefinedStep" : 20 } }, "config" : { } } } }
SDK代码示例
SDK代码示例如下。
升级集群至v1.23版本,并设置节点升级步长为20。
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 UpgradeClusterSolution { 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(); UpgradeClusterRequest request = new UpgradeClusterRequest(); request.withClusterId("<cluster_id>"); UpgradeClusterRequestBody body = new UpgradeClusterRequestBody(); InPlaceRollingUpdate inPlaceRollingUpdateStrategy = new InPlaceRollingUpdate(); inPlaceRollingUpdateStrategy.withUserDefinedStep(20); UpgradeStrategy strategyClusterUpgradeAction = new UpgradeStrategy(); strategyClusterUpgradeAction.withType("inPlaceRollingUpdate") .withInPlaceRollingUpdate(inPlaceRollingUpdateStrategy); ClusterUpgradeAction clusterUpgradeActionSpec = new ClusterUpgradeAction(); clusterUpgradeActionSpec.withStrategy(strategyClusterUpgradeAction) .withTargetVersion("v1.23"); UpgradeSpec specbody = new UpgradeSpec(); specbody.withClusterUpgradeAction(clusterUpgradeActionSpec); UpgradeClusterRequestMetadata metadatabody = new UpgradeClusterRequestMetadata(); metadatabody.withApiVersion("v3") .withKind("UpgradeTask"); body.withSpec(specbody); body.withMetadata(metadatabody); request.withBody(body); try { UpgradeClusterResponse response = client.upgradeCluster(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.23版本,并设置节点升级步长为20。
# 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 = UpgradeClusterRequest() request.cluster_id = "<cluster_id>" inPlaceRollingUpdateStrategy = InPlaceRollingUpdate( user_defined_step=20 ) strategyClusterUpgradeAction = UpgradeStrategy( type="inPlaceRollingUpdate", in_place_rolling_update=inPlaceRollingUpdateStrategy ) clusterUpgradeActionSpec = ClusterUpgradeAction( strategy=strategyClusterUpgradeAction, target_version="v1.23" ) specbody = UpgradeSpec( cluster_upgrade_action=clusterUpgradeActionSpec ) metadatabody = UpgradeClusterRequestMetadata( api_version="v3", kind="UpgradeTask" ) request.body = UpgradeClusterRequestBody( spec=specbody, metadata=metadatabody ) response = client.upgrade_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.23版本,并设置节点升级步长为20。
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.UpgradeClusterRequest{} request.ClusterId = "<cluster_id>" userDefinedStepInPlaceRollingUpdate:= int32(20) inPlaceRollingUpdateStrategy := &model.InPlaceRollingUpdate{ UserDefinedStep: &userDefinedStepInPlaceRollingUpdate, } strategyClusterUpgradeAction := &model.UpgradeStrategy{ Type: "inPlaceRollingUpdate", InPlaceRollingUpdate: inPlaceRollingUpdateStrategy, } clusterUpgradeActionSpec := &model.ClusterUpgradeAction{ Strategy: strategyClusterUpgradeAction, TargetVersion: "v1.23", } specbody := &model.UpgradeSpec{ ClusterUpgradeAction: clusterUpgradeActionSpec, } metadatabody := &model.UpgradeClusterRequestMetadata{ ApiVersion: "v3", Kind: "UpgradeTask", } request.Body = &model.UpgradeClusterRequestBody{ Spec: specbody, Metadata: metadatabody, } response, err := client.UpgradeCluster(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
表示集群升级任务下发成功。 |
错误码
请参见错误码。