更新时间:2024-04-23 GMT+08:00
分享

集群升级

功能介绍

集群升级。

  • 集群升级涉及多维度的组件升级操作,强烈建议统一通过CCE控制台执行交互式升级,降低集群升级过程的业务意外受损风险;

  • 当前集群升级相关接口受限开放。

调用方法

请参见如何调用API

URI

POST /api/v3/projects/{project_id}/clusters/{cluster_id}/operation/upgrade

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

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

cluster_id

String

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

请求参数

表2 请求Body参数

参数

是否必选

参数类型

描述

metadata

UpgradeClusterRequestMetadata object

升级元数据

spec

UpgradeSpec object

升级配置信息

表3 UpgradeClusterRequestMetadata

参数

是否必选

参数类型

描述

apiVersion

String

api版本,默认为v3

kind

String

资源类型,默认为UpgradeTask

表4 UpgradeSpec

参数

是否必选

参数类型

描述

clusterUpgradeAction

ClusterUpgradeAction object

集群升级配置

表5 ClusterUpgradeAction

参数

是否必选

参数类型

描述

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"

表6 UpgradeAddonConfig

参数

是否必选

参数类型

描述

addonTemplateName

String

插件名称

operation

String

执行动作,当前升级场景支持操作为"patch"

version

String

目标插件版本号

说明:

目标插件版本必须与目标集群版本配套 插件版本与集群版本配套关系见查询AddonTemplates列表]

values

Object

插件参数列表,Key:Value格式

表7 NodePriority

参数

是否必选

参数类型

描述

nodeSelector

NodeSelector object

节点标签选择器,选择一批节点

priority

Integer

该批次节点的优先级,默认值为0,优先级最低,数值越大优先级越高

表8 NodeSelector

参数

是否必选

参数类型

描述

key

String

标签键

value

Array of strings

标签值列表

operator

String

标签逻辑运算符

表9 UpgradeStrategy

参数

是否必选

参数类型

描述

type

String

升级策略类型,当前仅支持原地升级类型"inPlaceRollingUpdate"

inPlaceRollingUpdate

InPlaceRollingUpdate object

原地升级配置,指定原地升级策略类型时必选。

表10 InPlaceRollingUpdate

参数

是否必选

参数类型

描述

userDefinedStep

Integer

节点升级步长,取值范围为[1, 40],建议取值20

响应参数

状态码: 200

表11 响应Body参数

参数

参数类型

描述

metadata

UpgradeCluserResponseMetadata object

升级任务元数据信息

spec

UpgradeResponseSpec object

升级配置信息

表12 UpgradeCluserResponseMetadata

参数

参数类型

描述

uid

String

升级任务ID,可通过调用获取集群升级任务详情API查询进展

表13 UpgradeResponseSpec

参数

参数类型

描述

clusterUpgradeAction

ClusterUpgradeResponseAction object

集群升级配置

表14 ClusterUpgradeResponseAction

参数

参数类型

描述

version

String

当前集群版本

targetVersion

String

目标集群版本,例如"v1.23"

targetPlatformVersion

String

目标集群的平台版本号,表示集群版本(version)下的内部版本,不支持用户指定。

strategy

UpgradeStrategy object

升级策略

config

Object

升级过程中指定的集群配置

表15 UpgradeStrategy

参数

参数类型

描述

type

String

升级策略类型,当前仅支持原地升级类型"inPlaceRollingUpdate"

inPlaceRollingUpdate

InPlaceRollingUpdate object

原地升级配置,指定原地升级策略类型时必选。

表16 InPlaceRollingUpdate

参数

参数类型

描述

userDefinedStep

Integer

节点升级步长,取值范围为[1, 40],建议取值20

请求示例

升级集群至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
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");

        ICredential auth = new BasicCredentials()
                .withAk(ak)
                .withSk(sk);

        CceClient client = CceClient.newBuilder()
                .withCredential(auth)
                .withRegion(CceRegion.valueOf("<YOUR REGION>"))
                .build();
        UpgradeClusterRequest request = new UpgradeClusterRequest();
        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
# 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__":
    # 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 = __import__('os').getenv("CLOUD_SDK_AK")
    sk = __import__('os').getenv("CLOUD_SDK_SK")

    credentials = BasicCredentials(ak, sk) \

    client = CceClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(CceRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = UpgradeClusterRequest()
        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
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")

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := cce.NewCceClient(
        cce.CceClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.UpgradeClusterRequest{}
	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

表示集群升级任务下发成功。

错误码

请参见错误码

分享:

    相关文档

    相关产品