同步节点池
功能介绍
该API用于同步节点池中已有节点的配置
集群管理的URL格式为:https://Endpoint/uri。其中uri为资源路径,也即API访问的路径
调用方法
请参见如何调用API。
URI
POST /api/v3/projects/:projectid/clusters/{cluster_id}/nodepools/{nodepool_id}/operation/upgrade
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
参数解释: 项目ID,获取方式请参见如何获取接口URI中参数。 约束限制: 不涉及 取值范围: 账号的项目ID 默认取值: 不涉及 |
cluster_id |
是 |
String |
参数解释: 集群ID,获取方式请参见如何获取接口URI中参数。 约束限制: 不涉及 取值范围: 集群ID 默认取值: 不涉及 |
nodepool_id |
是 |
String |
参数解释: 节点池ID,获取方式请参见如何获取接口URI中参数。 约束限制: 不涉及 取值范围: 节点池ID 默认取值: 不涉及 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
Content-Type |
是 |
String |
参数解释: 消息体的类型(格式) 约束限制: GET方法不做校验 取值范围:
默认取值: 不涉及 |
X-Auth-Token |
是 |
String |
参数解释: 调用接口的认证方式分为Token和AK/SK两种,如果您使用的Token方式,此参数为必填,请填写Token的值,获取方式请参见获取token。 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
spec |
是 |
UpgradeNodePoolSpec object |
同步节点池请求详细参数 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
maxUnavailable |
是 |
Integer |
每批最大同步节点,取值范围[1-20]。节点升级时,允许节点不可用的最大数量。节点重置方式进行同步时节点将不可用,请合理设置该参数,尽量避免出现集群节点不可用数量过多导致Pod无法调度的情况。 |
nodeIDs |
否 |
Array of strings |
本次操作同步的节点池中选择的节点ID列表,获取方式请参见如何获取接口URI中参数。 |
nodePoolID |
是 |
String |
节点池ID,获取方式请参见如何获取接口URI中参数。 |
nodeTemplate |
否 |
同步节点池模板参数 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
lifeCycle |
是 |
NodeLifecycleConfig object |
节点自定义生命周期配置 |
login |
是 |
Login object |
参数解释: 节点的登录方式。密钥对和密码登录方式二者必选其一。 约束限制: 更新节点池时,不支持修改此参数。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
preInstall |
否 |
String |
安装前执行脚本。安装前/后执行脚本统一计算字符,转码后的字符总数不能超过10240。 输入的值需要经过Base64编码,方法如下: echo -n "待编码内容" | base64 |
postInstall |
否 |
String |
安装后执行脚本。安装前/后执行脚本统一计算字符,转码后的字符总数不能超过10240。 输入的值需要经过Base64编码,方法如下: echo -n "待编码内容" | base64 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
sshKey |
否 |
String |
参数解释: 选择密钥对方式登录时的密钥对名称。 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
userPassword |
否 |
UserPassword object |
参数解释: 选择密码方式登录时的账号密码信息,之后可通过此账号密码登录节点。 约束限制: 不涉及 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
username |
否 |
String |
参数解释: 登录账号,默认为“root”。 约束限制: 不涉及 取值范围: 不涉及 默认取值: root。 |
password |
是 |
String |
参数解释: 登录密码,若创建节点通过用户名密码方式,即使用该字段,则响应体中该字段作屏蔽展示。 约束限制: 创建节点时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 |
表示节点池同步已经被接受 |
错误码
请参见错误码。