获取集群证书
功能介绍
该API用于获取指定集群的证书信息。
接口约束
该接口适用于1.13及以上集群版本。
调用方法
请参见如何调用API。
URI
POST /api/v3/projects/{project_id}/clusters/{cluster_id}/clustercert
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
参数解释: 项目ID,获取方式请参见如何获取接口URI中参数。 约束限制: 不涉及 取值范围: 账号的项目ID 默认取值: 不涉及 |
cluster_id |
是 |
String |
参数解释: 集群ID,获取方式请参见如何获取接口URI中参数。 约束限制: 不涉及 取值范围: 集群ID 默认取值: 不涉及 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
Content-Type |
是 |
String |
参数解释: 消息体的类型(格式) 约束限制: GET方法不做校验 取值范围:
默认取值: 不涉及 |
X-Auth-Token |
是 |
String |
参数解释: 调用接口的认证方式分为Token和AK/SK两种,如果您使用的Token方式,此参数为必填,请填写Token的值,获取方式请参见获取token。 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
duration |
是 |
Integer |
集群证书有效时间,最小值为1天,最大值为5年,因此取值范围为1-1827(以天为单位,实际上限取决于5年内闰年的数量,例如5年内存在一个闰年则上限为1826天);若填-1则为最大值5年。 |
响应参数
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
Port-ID |
String |
集群控制节点端口ID |
参数 |
参数类型 |
描述 |
---|---|---|
kind |
String |
API类型,固定值“Config”,该值不可修改。 |
apiVersion |
String |
API版本,固定值“v1”。 |
preferences |
Object |
当前未使用该字段,当前默认为空。 |
clusters |
Array of Clusters objects |
集群列表。 |
users |
Array of Users objects |
存放了指定用户的一些证书信息和ClientKey信息。 |
contexts |
Array of Contexts objects |
上下文列表。 |
current-context |
String |
当前上下文,若存在publicIp(虚拟机弹性IP)时为 external; 若不存在publicIp为 internal。 |
参数 |
参数类型 |
描述 |
---|---|---|
name |
String |
集群名字。
|
cluster |
ClusterCert object |
集群信息。 |
参数 |
参数类型 |
描述 |
---|---|---|
server |
String |
服务器地址。 |
certificate-authority-data |
String |
证书授权数据。 |
insecure-skip-tls-verify |
Boolean |
不校验服务端证书,在 cluster 类型为 externalCluster 时,该值为 true。 |
参数 |
参数类型 |
描述 |
---|---|---|
client-certificate-data |
String |
客户端证书。 |
client-key-data |
String |
包含来自TLS客户端密钥文件的PEM编码数据。 |
参数 |
参数类型 |
描述 |
---|---|---|
name |
String |
上下文的名称。
|
context |
Context object |
上下文信息。 |
请求示例
申请30天有效的集群访问证书
{ "duration" : 30 }
响应示例
状态码: 200
表示成功获取指定集群的证书。证书文件格式参见kubernetes v1.Config结构
{ "kind" : "Config", "apiVersion" : "v1", "preferences" : { }, "clusters" : [ { "name" : "internalCluster", "cluster" : { "server" : "https://192.168.1.7:5443", "certificate-authority-data" : "Q2VydGlmaWNhdGU6******FTkQgQ0VSVElGSUNBVEUtLS0tLQo=" } } ], "users" : [ { "name" : "user", "user" : { "client-certificate-data" : "LS0tLS1CRUdJTiBDR******QVRFLS0tLS0K", "client-key-data" : "LS0tLS1CRUdJTi******BLRVktLS0tLQo=" } } ], "contexts" : [ { "name" : "internal", "context" : { "cluster" : "internalCluster", "user" : "user" } } ], "current-context" : "internal" }
SDK代码示例
SDK代码示例如下。
申请30天有效的集群访问证书
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 |
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 CreateKubernetesClusterCertSolution { 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(); CreateKubernetesClusterCertRequest request = new CreateKubernetesClusterCertRequest(); request.withClusterId("{cluster_id}"); CertDuration body = new CertDuration(); body.withDuration(30); request.withBody(body); try { CreateKubernetesClusterCertResponse response = client.createKubernetesClusterCert(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()); } } } |
申请30天有效的集群访问证书
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 |
# 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 = CreateKubernetesClusterCertRequest() request.cluster_id = "{cluster_id}" request.body = CertDuration( duration=30 ) response = client.create_kubernetes_cluster_cert(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
申请30天有效的集群访问证书
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 |
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.CreateKubernetesClusterCertRequest{} request.ClusterId = "{cluster_id}" request.Body = &model.CertDuration{ Duration: int32(30), } response, err := client.CreateKubernetesClusterCert(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
表示成功获取指定集群的证书。证书文件格式参见kubernetes v1.Config结构 |
错误码
请参见错误码。