Updated on 2024-09-30 GMT+08:00

Upgrading a Cluster

Function

This API is used to upgrade a cluster.

  • Cluster upgrade involves many operations on components. You are advised to upgrade your cluster on the CCE console, a more interactive and intuitive way to reduce operational risks.
  • Cluster upgrade APIs are available only upon request.

Calling Method

For details, see Calling APIs.

URI

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

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details about how to obtain the value, see How to Obtain Parameters in the API URI.

cluster_id

Yes

String

Cluster ID. For details about how to obtain the value, see How to Obtain Parameters in the API URI.

Request Parameters

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

metadata

Yes

UpgradeClusterRequestMetadata object

Upgrade metadata.

spec

Yes

UpgradeSpec object

Upgrade settings.

Table 3 UpgradeClusterRequestMetadata

Parameter

Mandatory

Type

Description

apiVersion

Yes

String

API version. Defaults to v3.

kind

Yes

String

Resource type. Defaults to UpgradeTask.

Table 4 UpgradeSpec

Parameter

Mandatory

Type

Description

clusterUpgradeAction

No

ClusterUpgradeAction object

Cluster upgrade settings.

Table 5 ClusterUpgradeAction

Parameter

Mandatory

Type

Description

addons

No

Array of UpgradeAddonConfig objects

Add-on configuration list.

nodeOrder

No

Map<String,Array<NodePriority>>

Upgrade sequence of nodes in the node pool.

NOTE:

key indicates the node pool ID. Defaults to DefaultPool.

nodePoolOrder

No

Map<String,Integer>

Upgrade sequence of a node pool, in key-value pairs.

NOTE:

key indicates the node pool ID. Defaults to DefaultPool.

value means the priority of a node pool. Defaults to 0, indicating the lowest priority. A larger value indicates a higher priority.

strategy

Yes

UpgradeStrategy object

Upgrade policy.

targetVersion

Yes

String

Target cluster version, for example, v1.23.

Table 6 UpgradeAddonConfig

Parameter

Mandatory

Type

Description

addonTemplateName

Yes

String

Add-on name.

operation

Yes

String

Execution action. For current upgrades, the value can be patch.

version

Yes

String

Target add-on version.

values

No

Map<String,Object>

Add-on parameter list, in key-value pairs.

Table 7 NodePriority

Parameter

Mandatory

Type

Description

nodeSelector

Yes

NodeSelector object

Node label selector, which selects a batch of nodes.

priority

Yes

Integer

Priority of this batch of nodes. Defaults to 0, indicating the lowest priority. A larger value indicates a higher priority.

Table 8 NodeSelector

Parameter

Mandatory

Type

Description

key

Yes

String

Label key.

value

No

Array of strings

Label value list.

operator

Yes

String

Logical operators of labels.

Table 9 UpgradeStrategy

Parameter

Mandatory

Type

Description

type

Yes

String

Upgrade policy type. Supports only inPlaceRollingUpdate.

inPlaceRollingUpdate

No

InPlaceRollingUpdate object

In-place upgrade settings. Mandatory when the in-place upgrade policy type is specified.

Table 10 InPlaceRollingUpdate

Parameter

Mandatory

Type

Description

userDefinedStep

No

Integer

Node upgrade step, from 1 to 40. Recommended: 20.

scope

No

String

Details:

Scope of the node upgrade batch

Constraints:

None

Options:

Cluster: If the scope is set to a cluster, the upgrade batch will remain unchanged throughout the entire upgrade process.

NodePool: If the scope is set to node pools, the upgrade batch will be reset for each individual node pool.

Default value:

Cluster

Response Parameters

Status code: 200

Table 11 Response body parameters

Parameter

Type

Description

metadata

UpgradeCluserResponseMetadata object

Upgrade task metadata

spec

UpgradeResponseSpec object

Upgrade settings

Table 12 UpgradeCluserResponseMetadata

Parameter

Type

Description

uid

String

Upgrade task ID. You can obtain the progress by calling the API for obtaining cluster upgrade task details.

Table 13 UpgradeResponseSpec

Parameter

Type

Description

clusterUpgradeAction

ClusterUpgradeResponseAction object

Cluster upgrade settings

Table 14 ClusterUpgradeResponseAction

Parameter

Type

Description

version

String

Current cluster version

targetVersion

String

Target cluster version, for example, v1.23.

targetPlatformVersion

String

Platform version of the target cluster, which is an internal version of the cluster version and cannot be specified.

strategy

UpgradeStrategyResponse object

Upgrade policies

config

Object

Cluster configuration specified during an upgrade

Table 15 UpgradeStrategyResponse

Parameter

Type

Description

type

String

Upgrade policy type

inPlaceRollingUpdate

InPlaceRollingUpdateResponse object

Detailed configuration of an in-place upgrade policy

Table 16 InPlaceRollingUpdateResponse

Parameter

Type

Description

userDefinedStep

Integer

Maximum number of nodes to be upgraded in a batch

scope

String

Scope of the node upgrade batch

Example Requests

Upgrade the cluster to v1.28 and set the node upgrade step to 20.

POST /autopilot/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"
    }
  }
}

Example Responses

Status code: 200

Cluster upgrade requested.

{
  "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 Sample Code

The SDK sample code is as follows.

Upgrade the cluster to v1.28 and set the node upgrade step to 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 UpgradeAutopilotClusterSolution {

    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();
        UpgradeAutopilotClusterRequest request = new UpgradeAutopilotClusterRequest();
        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 {
            UpgradeAutopilotClusterResponse response = client.upgradeAutopilotCluster(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());
        }
    }
}

Upgrade the cluster to v1.28 and set the node upgrade step to 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 = UpgradeAutopilotClusterRequest()
        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_autopilot_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)

Upgrade the cluster to v1.28 and set the node upgrade step to 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.UpgradeAutopilotClusterRequest{}
	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.UpgradeAutopilotCluster(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.

Status Codes

Status Code

Description

200

Cluster upgrade requested.

Error Codes

See Error Codes.