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

同步节点池

功能介绍

该API用于同步节点池中已有节点的配置

集群管理的URL格式为:https://Endpoint/uri。其中uri为资源路径,也即API访问的路径

调用方法

请参见如何调用API

URI

POST /api/v3/projects/:projectid/clusters/{cluster_id}/nodepools/{nodepool_id}/operation/upgrade

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

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

cluster_id

String

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

nodepool_id

String

节点池ID

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

Content-Type

String

消息体的类型(格式)

X-Auth-Token

String

调用接口的认证方式分为Token和AK/SK两种,如果您使用的Token方式,此参数为必填,请填写Token的值,获取方式请参见获取token

表3 请求Body参数

参数

是否必选

参数类型

描述

spec

UpgradeNodePoolSpec object

同步节点池请求详细参数

表4 UpgradeNodePoolSpec

参数

是否必选

参数类型

描述

maxUnavailable

Integer

每批最大同步节点,取值范围[1-20]。节点升级时,允许节点不可用的最大数量。节点重置方式进行同步时节点将不可用,请合理设置该参数,尽量避免出现集群节点不可用数量过多导致Pod无法调度的情况。

nodeIDs

Array of strings

本次操作同步的节点池中选择的节点ID列表,获取方式请参见如何获取接口URI中参数

nodePoolID

String

节点池ID,获取方式请参见如何获取接口URI中参数

nodeTemplate

UpgradeNodePoolSpecNodeTemplate object

同步节点池模板参数

表5 UpgradeNodePoolSpecNodeTemplate

参数

是否必选

参数类型

描述

lifecycle

NodeLifecycleConfig object

节点自定义生命周期配置

login

Login object

节点的登录方式。支持同时使用密钥对和密码登录方式。

说明:

更新节点池时,不支持修改此参数

表6 NodeLifecycleConfig

参数

是否必选

参数类型

描述

preInstall

String

安装前执行脚本。安装前/后执行脚本统一计算字符,转码后的字符总数不能超过10240。

输入的值需要经过Base64编码,方法如下:

echo -n "待编码内容" | base64

postInstall

String

安装后执行脚本。安装前/后执行脚本统一计算字符,转码后的字符总数不能超过10240。

输入的值需要经过Base64编码,方法如下:

echo -n "待编码内容" | base64
表7 Login

参数

是否必选

参数类型

描述

sshKey

String

选择密钥对方式登录时的密钥对名称。

userPassword

UserPassword object

选择密码方式登录时的账号密码信息,之后可通过此账号密码登录节点。

表8 UserPassword

参数

是否必选

参数类型

描述

username

String

登录账号,默认为“root”

password

String

登录密码,若创建节点通过用户名密码方式,即使用该字段,则响应体中该字段作屏蔽展示。

密码复杂度要求:

  • 长度为8-26位。

  • 密码至少必须包含大写字母、小写字母、数字和特殊字符(!@$%^-_=+[{}]:,./?)中的三种。

  • 密码不能包含用户名或用户名的逆序。

    创建节点时password字段需要加盐加密,具体方法请参见创建节点时password字段加盐加密

响应参数

请求示例

  • 同步节点池(自建节点池)

    {
      "spec" : {
        "maxUnavailable" : 1,
        "nodeIDs" : [ "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "bbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbb" ],
        "nodePoolID" : "cccccccc-cccc-cccc-cccc-cccccccccccc"
      }
    }
  • 同步节点池(默认节点池)

    {
      "spec" : {
        "maxUnavailable" : 1,
        "nodeIDs" : [ "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "bbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbb" ],
        "nodePoolID" : "DefaultPool",
        "nodeTemplate" : {
          "lifeCycle" : {
            "preInstall" : "ZWNobyAx",
            "postInstall" : "ZWNobyAx"
          },
          "login" : {
            "userPassword" : {
              "password" : "xxxxx",
              "username" : "root"
            }
          }
        }
      }
    }

响应示例

SDK代码示例

SDK代码示例如下。

  • 同步节点池(自建节点池)

     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 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 UpgradeNodePoolSolution {
    
        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();
            UpgradeNodePoolRequest request = new UpgradeNodePoolRequest();
            request.withClusterId("{cluster_id}");
            request.withNodepoolId("{nodepool_id}");
            UpgradeNodePool body = new UpgradeNodePool();
            List<String> listSpecNodeIDs = new ArrayList<>();
            listSpecNodeIDs.add("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa");
            listSpecNodeIDs.add("bbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbb");
            NodePoolUpgradeSpec specbody = new NodePoolUpgradeSpec();
            specbody.withNodePoolID("cccccccc-cccc-cccc-cccc-cccccccccccc")
                .withNodeIDs(listSpecNodeIDs)
                .withMaxUnavailable(1);
            body.withSpec(specbody);
            request.withBody(body);
            try {
                UpgradeNodePoolResponse response = client.upgradeNodePool(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());
            }
        }
    }
    
  • 同步节点池(默认节点池)

     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
    66
    67
    68
    69
    70
    71
    72
    73
    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 UpgradeNodePoolSolution {
    
        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();
            UpgradeNodePoolRequest request = new UpgradeNodePoolRequest();
            request.withClusterId("{cluster_id}");
            request.withNodepoolId("{nodepool_id}");
            UpgradeNodePool body = new UpgradeNodePool();
            NodeTemplateLifeCycle lifeCycleNodeTemplate = new NodeTemplateLifeCycle();
            lifeCycleNodeTemplate.withPreInstall("ZWNobyAx")
                .withPostInstall("ZWNobyAx");
            NodeTemplateLoginUserPassword userPasswordLogin = new NodeTemplateLoginUserPassword();
            userPasswordLogin.withUsername("root")
                .withPassword("xxxxx");
            NodeTemplateLogin loginNodeTemplate = new NodeTemplateLogin();
            loginNodeTemplate.withUserPassword(userPasswordLogin);
            NodeTemplate nodeTemplateSpec = new NodeTemplate();
            nodeTemplateSpec.withLogin(loginNodeTemplate)
                .withLifeCycle(lifeCycleNodeTemplate);
            List<String> listSpecNodeIDs = new ArrayList<>();
            listSpecNodeIDs.add("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa");
            listSpecNodeIDs.add("bbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbb");
            NodePoolUpgradeSpec specbody = new NodePoolUpgradeSpec();
            specbody.withNodePoolID("DefaultPool")
                .withNodeIDs(listSpecNodeIDs)
                .withNodeTemplate(nodeTemplateSpec)
                .withMaxUnavailable(1);
            body.withSpec(specbody);
            request.withBody(body);
            try {
                UpgradeNodePoolResponse response = client.upgradeNodePool(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());
            }
        }
    }
    
  • 同步节点池(自建节点池)

     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
    # 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 = UpgradeNodePoolRequest()
            request.cluster_id = "{cluster_id}"
            request.nodepool_id = "{nodepool_id}"
            listNodeIDsSpec = [
                "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
                "bbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbb"
            ]
            specbody = NodePoolUpgradeSpec(
                node_pool_id="cccccccc-cccc-cccc-cccc-cccccccccccc",
                node_i_ds=listNodeIDsSpec,
                max_unavailable=1
            )
            request.body = UpgradeNodePool(
                spec=specbody
            )
            response = client.upgrade_node_pool(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 同步节点池(默认节点池)

     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
    # 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 = UpgradeNodePoolRequest()
            request.cluster_id = "{cluster_id}"
            request.nodepool_id = "{nodepool_id}"
            lifeCycleNodeTemplate = NodeTemplateLifeCycle(
                pre_install="ZWNobyAx",
                post_install="ZWNobyAx"
            )
            userPasswordLogin = NodeTemplateLoginUserPassword(
                username="root",
                password="xxxxx"
            )
            loginNodeTemplate = NodeTemplateLogin(
                user_password=userPasswordLogin
            )
            nodeTemplateSpec = NodeTemplate(
                login=loginNodeTemplate,
                life_cycle=lifeCycleNodeTemplate
            )
            listNodeIDsSpec = [
                "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
                "bbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbb"
            ]
            specbody = NodePoolUpgradeSpec(
                node_pool_id="DefaultPool",
                node_i_ds=listNodeIDsSpec,
                node_template=nodeTemplateSpec,
                max_unavailable=1
            )
            request.body = UpgradeNodePool(
                spec=specbody
            )
            response = client.upgrade_node_pool(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 同步节点池(自建节点池)

     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
    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.UpgradeNodePoolRequest{}
    	request.ClusterId = "{cluster_id}"
    	request.NodepoolId = "{nodepool_id}"
    	var listNodeIDsSpec = []string{
            "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
    	    "bbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbb",
        }
    	maxUnavailableSpec:= int32(1)
    	specbody := &model.NodePoolUpgradeSpec{
    		NodePoolID: "cccccccc-cccc-cccc-cccc-cccccccccccc",
    		NodeIDs: &listNodeIDsSpec,
    		MaxUnavailable: &maxUnavailableSpec,
    	}
    	request.Body = &model.UpgradeNodePool{
    		Spec: specbody,
    	}
    	response, err := client.UpgradeNodePool(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 同步节点池(默认节点池)

     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
    66
    67
    68
    69
    70
    71
    72
    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.UpgradeNodePoolRequest{}
    	request.ClusterId = "{cluster_id}"
    	request.NodepoolId = "{nodepool_id}"
    	preInstallLifeCycle:= "ZWNobyAx"
    	postInstallLifeCycle:= "ZWNobyAx"
    	lifeCycleNodeTemplate := &model.NodeTemplateLifeCycle{
    		PreInstall: &preInstallLifeCycle,
    		PostInstall: &postInstallLifeCycle,
    	}
    	usernameUserPassword:= "root"
    	passwordUserPassword:= "xxxxx"
    	userPasswordLogin := &model.NodeTemplateLoginUserPassword{
    		Username: &usernameUserPassword,
    		Password: &passwordUserPassword,
    	}
    	loginNodeTemplate := &model.NodeTemplateLogin{
    		UserPassword: userPasswordLogin,
    	}
    	nodeTemplateSpec := &model.NodeTemplate{
    		Login: loginNodeTemplate,
    		LifeCycle: lifeCycleNodeTemplate,
    	}
    	var listNodeIDsSpec = []string{
            "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
    	    "bbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbb",
        }
    	maxUnavailableSpec:= int32(1)
    	specbody := &model.NodePoolUpgradeSpec{
    		NodePoolID: "DefaultPool",
    		NodeIDs: &listNodeIDsSpec,
    		NodeTemplate: nodeTemplateSpec,
    		MaxUnavailable: &maxUnavailableSpec,
    	}
    	request.Body = &model.UpgradeNodePool{
    		Spec: specbody,
    	}
    	response, err := client.UpgradeNodePool(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

表示节点池同步已经被接受

错误码

请参见错误码

相关文档