集群升级
功能介绍
集群升级。
- 集群升级涉及多维度的组件升级操作,强烈建议统一通过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 |
是 |
UpgradeSpec object |
升级配置信息 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
apiVersion |
是 |
String |
api版本,默认为v3 |
kind |
是 |
String |
资源类型,默认为UpgradeTask |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
addons |
否 |
Array of UpgradeAddonConfig objects |
插件配置列表 |
nodeOrder |
否 |
Map<String,Array<NodePriority>> |
节点池内节点升级顺序配置。
说明:
key表示节点池ID,默认节点池取值为"DefaultPool" |
nodePoolOrder |
否 |
Map<String,Integer> |
节点池升级顺序配置,key/value对格式。
说明:
key表示节点池ID,默认节点池取值为"DefaultPool" value表示对应节点池的优先级,默认值为0,优先级最低,数值越大优先级越高 |
strategy |
是 |
UpgradeStrategy object |
升级策略 |
targetVersion |
是 |
String |
目标集群版本,例如"v1.23" |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
addonTemplateName |
是 |
String |
插件名称 |
operation |
是 |
String |
执行动作,当前升级场景支持操作为"patch" |
version |
是 |
String |
目标插件版本号
说明:
目标插件版本必须与目标集群版本配套 Standard和Turbo集群的插件版本与集群版本配套关系见查询AddonTemplates列表 |
values |
否 |
Object |
插件参数列表,Key:Value格式 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
nodeSelector |
是 |
NodeSelector object |
节点标签选择器,选择一批节点 |
priority |
是 |
Integer |
该批次节点的优先级,默认值为0,优先级最低,数值越大优先级越高 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
key |
是 |
String |
标签键 |
value |
否 |
Array of strings |
标签值列表 |
operator |
是 |
String |
标签逻辑运算符 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
type |
是 |
String |
升级策略类型,当前仅支持原地升级类型"inPlaceRollingUpdate" |
inPlaceRollingUpdate |
否 |
InPlaceRollingUpdate object |
原地升级配置,指定原地升级策略类型时必选。 |
响应参数
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
metadata |
升级任务元数据信息 |
|
spec |
UpgradeResponseSpec object |
升级配置信息 |
参数 |
参数类型 |
描述 |
---|---|---|
version |
String |
当前集群版本 |
targetVersion |
String |
目标集群版本,例如"v1.23" |
targetPlatformVersion |
String |
目标集群的平台版本号,表示集群版本(version)下的内部版本,不支持用户指定。 |
strategy |
UpgradeStrategy object |
升级策略 |
config |
Object |
升级过程中指定的集群配置 |
参数 |
参数类型 |
描述 |
---|---|---|
type |
String |
升级策略类型,当前仅支持原地升级类型"inPlaceRollingUpdate" |
inPlaceRollingUpdate |
InPlaceRollingUpdate 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。
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 |
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) { // 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(); 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。
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 |
# 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 = 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。
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 |
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 := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := cce.NewCceClient( cce.CceClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). 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 |
表示集群升级任务下发成功。 |
错误码
请参见错误码。