创建网格 - CreateMesh
功能介绍
该API用于创建一个网格。
调用方法
请参见如何调用API。
授权信息
账号具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权,具体权限要求请参见权限和授权项。
- 如果使用身份策略授权,需具备如下身份策略权限。
URI
POST /v1/{project_id}/meshes
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
project_id |
是 |
String |
项目ID。 |
请求参数
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
Content-Type |
是 |
String |
消息体的类型(格式)。 取值范围: |
|
X-Auth-Token |
是 |
String |
调用接口的认证方式分为Token和AK/SK两种,如果您使用的Token方式,此参数为必填,请填写Token的值。 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
apiVersion |
是 |
String |
API版本,固定值“v1”,该值不可修改 |
|
kind |
是 |
String |
API类型,固定值“Mesh”或“mesh”,该值不可修改 |
|
metadata |
是 |
MeshMetadata object |
网格的基本信息,为集合类的元素类型,包含一组由不同名称定义的属性 |
|
spec |
是 |
MeshSpec object |
集合类的元素类型,您对需要管理的网格对象进行详细描述的主体部分都在spec中给出。ASM通过spec的描述来创建或更新对象 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
name |
是 |
String |
网格名称。 命名规则:以小写字母开头,由小写字母、数字、中划线(-)组成,长度范围4-64位,且不能以中划线(-)结尾 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
type |
是 |
String |
网格类型。 取值范围: |
|
version |
是 |
String |
网格版本。 |
|
extendParams |
是 |
MeshExtendParams object |
服务网格扩展信息。 |
|
ipv6Enable |
否 |
Boolean |
网格是否支持IPV6 |
|
tags |
否 |
Array of MeshTags objects |
网格资源标签。如果需要配置资源标签,请确认当前region的TMS服务已上线。 |
|
config |
否 |
MeshConfig object |
网格配置。 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
clusterID |
是 |
String |
集群ID,资源唯一标识,通过该ID查询需要添加的集群 |
|
injection |
否 |
InjectionConfig object |
sidecar注入配置 |
|
installation |
是 |
InstallationConfig object |
网格组件安装配置 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
key |
是 |
String |
Key值 |
|
operator |
是 |
String |
操作符,仅支持取值"In" |
|
values |
是 |
Array of strings |
Value值 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
key |
否 |
String |
Key值。 不能为空,最多支持128个字符 可用UTF-8格式表示的汉字、字母、数字和空格 支持部分特殊字符:_.:/=+-@ 不能以"sys"开头 |
|
value |
否 |
String |
Value值。 可以为空但不能缺省,最多支持255个字符 可用UTF-8格式表示的汉字、字母、数字和空格 支持部分特殊字符:_.:/=+-@ |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
proxyConfig |
否 |
ProxyConfig object |
网格数据面配置 |
|
telemetryConfig |
否 |
TelemetryConfig object |
网格的可观测性配置 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
includeIPRanges |
否 |
String |
拦截对外访问的地址范围,以半角英文逗号(,)分隔的IP网段 |
|
excludeIPRanges |
否 |
String |
排除拦截对外访问的地址范围,以半角英文逗号(,)分隔的IP网段 |
|
excludeOutboundPorts |
否 |
String |
排除拦截对外访问端口,以半角英文逗号(,)分隔的出站端口列表 |
|
excludeInboundPorts |
否 |
String |
排除拦截访问服务的端口,以半角英文逗号(,)分隔的入站端口列表 |
|
includeOutboundPorts |
否 |
String |
拦截对外访问端口,以半角英文逗号(,)分隔的出站端口列表 |
|
includeInboundPorts |
否 |
String |
拦截访问服务的端口,以半角英文逗号(,)分隔的入站端口列表 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
metrics |
否 |
Metric object |
应用指标配置,用于上报ASM网格指标数据。如果要启用该配置,集群需安装云原生监控插件。 |
|
accessLogging |
否 |
AccessLogging object |
AccessLog配置,用于上报ASM网格内Istio代理的访问日志。如果要启用该配置,集群需安装云原生日志采集插件。 |
|
tracing |
否 |
Tracing object |
Tracing配置,用于上报ASM网格内的调用链数据。 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
logGroupID |
否 |
String |
AccessLog日志组ID |
|
logStreamID |
否 |
String |
AccessLog输出日志流ID |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
randomSamplingPercentage |
否 |
Float |
tracing采样率 |
|
defaultProviders |
否 |
Array of strings |
tracing默认上报的provider名称,必须与extensionProviders中的name字段匹配,或使用ASM预设的provider "apm-otel"。 如果使用"apm-otel",需确认当前region已支持APM2.0且网格版本大于1.18。 |
|
extensionProviders |
否 |
Array of TracingExtensionProvider objects |
用户自配置provider,目前支持zipkin协议。 如果用户配置zipkin协议的provider,请保证网格版本大于等于1.15。 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
name |
否 |
String |
provider实例name |
|
zipkin |
否 |
ZipkinTracingProvider object |
zipkin协议provider自有配置 |
响应参数
状态码:201
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
apiVersion |
String |
API版本,固定值“v1”,该值不可修改 |
|
kind |
String |
API类型,固定值“Mesh”或“mesh”,该值不可修改 |
|
metadata |
MeshMetadata object |
网格的基本信息,为集合类的元素类型,包含一组由不同名称定义的属性 |
|
spec |
MeshSpec object |
集合类的元素类型,您对需要管理的网格对象进行详细描述的主体部分都在spec中给出。ASM通过spec的描述来创建或更新对象 |
|
status |
MeshStatus object |
集合类的元素类型,用于记录对象在系统中的当前状态信息。 该对象为系统自动生成,不需要用户填写 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
name |
String |
网格名称。 命名规则:以小写字母开头,由小写字母、数字、中划线(-)组成,长度范围4-64位,且不能以中划线(-)结尾 |
|
uid |
String |
网格ID,资源唯一标识,创建成功后自动生成,填写无效 |
|
creationTimestamp |
String |
网格创建时间 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
type |
String |
网格类型。 取值范围: |
|
version |
String |
网格版本。 |
|
extendParams |
MeshExtendParams object |
服务网格扩展信息。 |
|
ipv6Enable |
Boolean |
网格是否支持IPV6 |
|
tags |
Array of MeshTags objects |
网格资源标签。如果需要配置资源标签,请确认当前region的TMS服务已上线。 |
|
config |
MeshConfig object |
网格配置。 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
clusterID |
String |
集群ID,资源唯一标识,通过该ID查询需要添加的集群 |
|
injection |
InjectionConfig object |
sidecar注入配置 |
|
installation |
InstallationConfig object |
网格组件安装配置 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
key |
String |
Key值 |
|
operator |
String |
操作符,仅支持取值"In" |
|
values |
Array of strings |
Value值 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
key |
String |
Key值。 不能为空,最多支持128个字符 可用UTF-8格式表示的汉字、字母、数字和空格 支持部分特殊字符:_.:/=+-@ 不能以"sys"开头 |
|
value |
String |
Value值。 可以为空但不能缺省,最多支持255个字符 可用UTF-8格式表示的汉字、字母、数字和空格 支持部分特殊字符:_.:/=+-@ |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
proxyConfig |
ProxyConfig object |
网格数据面配置 |
|
telemetryConfig |
TelemetryConfig object |
网格的可观测性配置 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
includeIPRanges |
String |
拦截对外访问的地址范围,以半角英文逗号(,)分隔的IP网段 |
|
excludeIPRanges |
String |
排除拦截对外访问的地址范围,以半角英文逗号(,)分隔的IP网段 |
|
excludeOutboundPorts |
String |
排除拦截对外访问端口,以半角英文逗号(,)分隔的出站端口列表 |
|
excludeInboundPorts |
String |
排除拦截访问服务的端口,以半角英文逗号(,)分隔的入站端口列表 |
|
includeOutboundPorts |
String |
拦截对外访问端口,以半角英文逗号(,)分隔的出站端口列表 |
|
includeInboundPorts |
String |
拦截访问服务的端口,以半角英文逗号(,)分隔的入站端口列表 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
metrics |
Metric object |
应用指标配置,用于上报ASM网格指标数据。如果要启用该配置,集群需安装云原生监控插件。 |
|
accessLogging |
AccessLogging object |
AccessLog配置,用于上报ASM网格内Istio代理的访问日志。如果要启用该配置,集群需安装云原生日志采集插件。 |
|
tracing |
Tracing object |
Tracing配置,用于上报ASM网格内的调用链数据。 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
randomSamplingPercentage |
Float |
tracing采样率 |
|
defaultProviders |
Array of strings |
tracing默认上报的provider名称,必须与extensionProviders中的name字段匹配,或使用ASM预设的provider "apm-otel"。 如果使用"apm-otel",需确认当前region已支持APM2.0且网格版本大于1.18。 |
|
extensionProviders |
Array of TracingExtensionProvider objects |
用户自配置provider,目前支持zipkin协议。 如果用户配置zipkin协议的provider,请保证网格版本大于等于1.15。 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
name |
String |
provider实例name |
|
zipkin |
ZipkinTracingProvider object |
zipkin协议provider自有配置 |
状态码:400
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
errorCode |
String |
错误码 |
|
errorMsg |
String |
错误描述 |
状态码:409
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
errorCode |
String |
错误码 |
|
errorMsg |
String |
错误描述 |
状态码:500
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
errorCode |
String |
错误码 |
|
errorMsg |
String |
错误描述 |
请求示例
创建网格
POST /v1/719217bc273743xxxxxxxxae8bc34480/meshes
{
"apiVersion" : "v1",
"kind" : "Mesh",
"metadata" : {
"name" : "mesh-test-api"
},
"spec" : {
"type" : "InCluster",
"version" : "1.18.7-r5",
"extendParams" : {
"clusters" : [ {
"clusterID" : "cb0ef541-xxxx-xxxx-xxxx-0255ac1001b7",
"installation" : {
"nodes" : {
"fieldSelector" : {
"key" : "UID",
"operator" : "In",
"values" : [ "1c531b0c-xxxx-xxxx-xxxx-0255ac100b08" ]
}
}
},
"injection" : {
"namespaces" : {
"fieldSelector" : {
"key" : "Name",
"operator" : "In",
"values" : [ "default" ]
}
}
}
} ]
},
"config" : {
"proxyConfig" : {
"includeIPRanges" : "10.247.0.0/16"
},
"telemetryConfig" : {
"metrics" : {
"aom" : [ {
"instanceID" : "602a5b7e-xxxx-xxxx-xxxx-4268c35b0424"
} ]
},
"accessLogging" : {
"lts" : [ {
"logGroupID" : "b884eaeb-xxxx-xxxx-xxxx-f442de73c392",
"logStreamID" : "362e11e8-xxxx-xxxx-xxxx-0afdc68da7d2"
} ]
},
"tracing" : {
"randomSamplingPercentage" : 1,
"defaultProviders" : [ "zipkin" ],
"extensionProviders" : [ {
"name" : "zipkin",
"zipkin" : {
"service" : "zipkin.monitoring.svc.cluster.local",
"port" : 9411
}
} ]
}
}
}
}
}
响应示例
状态码:201
表示创建网格任务下发成功,开始创建网格
{
"kind" : "Mesh",
"apiVersion" : "v1",
"metadata" : {
"name" : "mesh-test-api",
"uid" : "a1efdc3e-xxxx-xxxx-xxxx-94bef433347e",
"creationTimestamp" : "2025-04-10T07:48:37Z"
},
"spec" : {
"type" : "InCluster",
"version" : "1.18.7-r5",
"config" : {
"telemetryConfig" : {
"metrics" : {
"aom" : [ {
"instanceID" : "602a5b7e-xxxx-xxxx-xxxx-4268c35b0424"
} ]
},
"accessLogging" : {
"lts" : [ {
"logGroupID" : "b884eaeb-xxxx-xxxx-xxxx-f442de73c392",
"logStreamID" : "362e11e8-xxxx-xxxx-xxxx-0afdc68da7d2"
} ]
},
"tracing" : {
"randomSamplingPercentage" : 1,
"defaultProviders" : [ "zipkin" ],
"extensionProviders" : [ {
"name" : "zipkin",
"zipkin" : {
"service" : "zipkin.monitoring.svc.cluster.local",
"port" : 9411
}
} ]
}
},
"proxyConfig" : {
"includeIPRanges" : "10.247.0.0/16"
}
},
"extendParams" : {
"clusters" : [ {
"clusterID" : "cb0ef541-xxxx-xxxx-xxxx-0255ac1001b7"
} ]
}
},
"status" : {
"phase" : "Creating"
}
}
SDK代码示例
SDK代码示例如下。
Java
创建网格
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
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.asm.v1.region.AsmRegion; import com.huaweicloud.sdk.asm.v1.*; import com.huaweicloud.sdk.asm.v1.model.*; import java.util.List; import java.util.ArrayList; public class CreateMeshSolution { 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); AsmClient client = AsmClient.newBuilder() .withCredential(auth) .withRegion(AsmRegion.valueOf("<YOUR REGION>")) .build(); CreateMeshRequest request = new CreateMeshRequest(); Mesh body = new Mesh(); ZipkinTracingProvider zipkinExtensionProviders = new ZipkinTracingProvider(); zipkinExtensionProviders.withService("zipkin.monitoring.svc.cluster.local") .withPort(9411); List<TracingExtensionProvider> listTracingExtensionProviders = new ArrayList<>(); listTracingExtensionProviders.add( new TracingExtensionProvider() .withName("zipkin") .withZipkin(zipkinExtensionProviders) ); List<String> listTracingDefaultProviders = new ArrayList<>(); listTracingDefaultProviders.add("zipkin"); Tracing tracingTelemetryConfig = new Tracing(); tracingTelemetryConfig.withRandomSamplingPercentage(1f) .withDefaultProviders(listTracingDefaultProviders) .withExtensionProviders(listTracingExtensionProviders); List<LtsConfig> listAccessLoggingLts = new ArrayList<>(); listAccessLoggingLts.add( new LtsConfig() .withLogGroupID("b884eaeb-xxxx-xxxx-xxxx-f442de73c392") .withLogStreamID("362e11e8-xxxx-xxxx-xxxx-0afdc68da7d2") ); AccessLogging accessLoggingTelemetryConfig = new AccessLogging(); accessLoggingTelemetryConfig.withLts(listAccessLoggingLts); List<Aom> listMetricsAom = new ArrayList<>(); listMetricsAom.add( new Aom() .withInstanceID("602a5b7e-xxxx-xxxx-xxxx-4268c35b0424") ); Metric metricsTelemetryConfig = new Metric(); metricsTelemetryConfig.withAom(listMetricsAom); TelemetryConfig telemetryConfigConfig = new TelemetryConfig(); telemetryConfigConfig.withMetrics(metricsTelemetryConfig) .withAccessLogging(accessLoggingTelemetryConfig) .withTracing(tracingTelemetryConfig); ProxyConfig proxyConfigConfig = new ProxyConfig(); proxyConfigConfig.withIncludeIPRanges("10.247.0.0/16"); MeshConfig configSpec = new MeshConfig(); configSpec.withProxyConfig(proxyConfigConfig) .withTelemetryConfig(telemetryConfigConfig); List<String> listFieldSelectorValues = new ArrayList<>(); listFieldSelectorValues.add("1c531b0c-xxxx-xxxx-xxxx-0255ac100b08"); FieldSelector fieldSelectorNodes = new FieldSelector(); fieldSelectorNodes.withKey("UID") .withOperator("In") .withValues(listFieldSelectorValues); Selector nodesInstallation = new Selector(); nodesInstallation.withFieldSelector(fieldSelectorNodes); InstallationConfig installationClusters = new InstallationConfig(); installationClusters.withNodes(nodesInstallation); List<String> listFieldSelectorValues1 = new ArrayList<>(); listFieldSelectorValues1.add("default"); FieldSelector fieldSelectorNamespaces = new FieldSelector(); fieldSelectorNamespaces.withKey("Name") .withOperator("In") .withValues(listFieldSelectorValues1); Selector namespacesInjection = new Selector(); namespacesInjection.withFieldSelector(fieldSelectorNamespaces); InjectionConfig injectionClusters = new InjectionConfig(); injectionClusters.withNamespaces(namespacesInjection); List<MeshCluster> listExtendParamsClusters = new ArrayList<>(); listExtendParamsClusters.add( new MeshCluster() .withClusterID("cb0ef541-xxxx-xxxx-xxxx-0255ac1001b7") .withInjection(injectionClusters) .withInstallation(installationClusters) ); MeshExtendParams extendParamsSpec = new MeshExtendParams(); extendParamsSpec.withClusters(listExtendParamsClusters); MeshSpec specbody = new MeshSpec(); specbody.withType(MeshSpec.TypeEnum.fromValue("InCluster")) .withVersion("1.18.7-r5") .withExtendParams(extendParamsSpec) .withConfig(configSpec); MeshMetadata metadatabody = new MeshMetadata(); metadatabody.withName("mesh-test-api"); body.withSpec(specbody); body.withMetadata(metadatabody); body.withKind("Mesh"); body.withApiVersion("v1"); request.withBody(body); try { CreateMeshResponse response = client.createMesh(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()); } } } |
Python
创建网格
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkasm.v1.region.asm_region import AsmRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkasm.v1 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 = AsmClient.new_builder() \ .with_credentials(credentials) \ .with_region(AsmRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreateMeshRequest() zipkinExtensionProviders = ZipkinTracingProvider( service="zipkin.monitoring.svc.cluster.local", port=9411 ) listExtensionProvidersTracing = [ TracingExtensionProvider( name="zipkin", zipkin=zipkinExtensionProviders ) ] listDefaultProvidersTracing = [ "zipkin" ] tracingTelemetryConfig = Tracing( random_sampling_percentage=1, default_providers=listDefaultProvidersTracing, extension_providers=listExtensionProvidersTracing ) listLtsAccessLogging = [ LtsConfig( log_group_id="b884eaeb-xxxx-xxxx-xxxx-f442de73c392", log_stream_id="362e11e8-xxxx-xxxx-xxxx-0afdc68da7d2" ) ] accessLoggingTelemetryConfig = AccessLogging( lts=listLtsAccessLogging ) listAomMetrics = [ Aom( instance_id="602a5b7e-xxxx-xxxx-xxxx-4268c35b0424" ) ] metricsTelemetryConfig = Metric( aom=listAomMetrics ) telemetryConfigConfig = TelemetryConfig( metrics=metricsTelemetryConfig, access_logging=accessLoggingTelemetryConfig, tracing=tracingTelemetryConfig ) proxyConfigConfig = ProxyConfig( include_ip_ranges="10.247.0.0/16" ) configSpec = MeshConfig( proxy_config=proxyConfigConfig, telemetry_config=telemetryConfigConfig ) listValuesFieldSelector = [ "1c531b0c-xxxx-xxxx-xxxx-0255ac100b08" ] fieldSelectorNodes = FieldSelector( key="UID", operator="In", values=listValuesFieldSelector ) nodesInstallation = Selector( field_selector=fieldSelectorNodes ) installationClusters = InstallationConfig( nodes=nodesInstallation ) listValuesFieldSelector1 = [ "default" ] fieldSelectorNamespaces = FieldSelector( key="Name", operator="In", values=listValuesFieldSelector1 ) namespacesInjection = Selector( field_selector=fieldSelectorNamespaces ) injectionClusters = InjectionConfig( namespaces=namespacesInjection ) listClustersExtendParams = [ MeshCluster( cluster_id="cb0ef541-xxxx-xxxx-xxxx-0255ac1001b7", injection=injectionClusters, installation=installationClusters ) ] extendParamsSpec = MeshExtendParams( clusters=listClustersExtendParams ) specbody = MeshSpec( type="InCluster", version="1.18.7-r5", extend_params=extendParamsSpec, config=configSpec ) metadatabody = MeshMetadata( name="mesh-test-api" ) request.body = Mesh( spec=specbody, metadata=metadatabody, kind="Mesh", api_version="v1" ) response = client.create_mesh(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
Go
创建网格
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" asm "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/asm/v1" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/asm/v1/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/asm/v1/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 := asm.NewAsmClient( asm.AsmClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreateMeshRequest{} serviceZipkin:= "zipkin.monitoring.svc.cluster.local" portZipkin:= int32(9411) zipkinExtensionProviders := &model.ZipkinTracingProvider{ Service: &serviceZipkin, Port: &portZipkin, } nameExtensionProviders:= "zipkin" var listExtensionProvidersTracing = []model.TracingExtensionProvider{ { Name: &nameExtensionProviders, Zipkin: zipkinExtensionProviders, }, } var listDefaultProvidersTracing = []string{ "zipkin", } randomSamplingPercentageTracing:= float32(1) tracingTelemetryConfig := &model.Tracing{ RandomSamplingPercentage: &randomSamplingPercentageTracing, DefaultProviders: &listDefaultProvidersTracing, ExtensionProviders: &listExtensionProvidersTracing, } logGroupIDLts:= "b884eaeb-xxxx-xxxx-xxxx-f442de73c392" logStreamIDLts:= "362e11e8-xxxx-xxxx-xxxx-0afdc68da7d2" var listLtsAccessLogging = []model.LtsConfig{ { LogGroupID: &logGroupIDLts, LogStreamID: &logStreamIDLts, }, } accessLoggingTelemetryConfig := &model.AccessLogging{ Lts: &listLtsAccessLogging, } var listAomMetrics = []model.Aom{ { InstanceID: "602a5b7e-xxxx-xxxx-xxxx-4268c35b0424", }, } metricsTelemetryConfig := &model.Metric{ Aom: &listAomMetrics, } telemetryConfigConfig := &model.TelemetryConfig{ Metrics: metricsTelemetryConfig, AccessLogging: accessLoggingTelemetryConfig, Tracing: tracingTelemetryConfig, } includeIPRangesProxyConfig:= "10.247.0.0/16" proxyConfigConfig := &model.ProxyConfig{ IncludeIPRanges: &includeIPRangesProxyConfig, } configSpec := &model.MeshConfig{ ProxyConfig: proxyConfigConfig, TelemetryConfig: telemetryConfigConfig, } var listValuesFieldSelector = []string{ "1c531b0c-xxxx-xxxx-xxxx-0255ac100b08", } fieldSelectorNodes := &model.FieldSelector{ Key: "UID", Operator: "In", Values: listValuesFieldSelector, } nodesInstallation := &model.Selector{ FieldSelector: fieldSelectorNodes, } installationClusters := &model.InstallationConfig{ Nodes: nodesInstallation, } var listValuesFieldSelector1 = []string{ "default", } fieldSelectorNamespaces := &model.FieldSelector{ Key: "Name", Operator: "In", Values: listValuesFieldSelector1, } namespacesInjection := &model.Selector{ FieldSelector: fieldSelectorNamespaces, } injectionClusters := &model.InjectionConfig{ Namespaces: namespacesInjection, } var listClustersExtendParams = []model.MeshCluster{ { ClusterID: "cb0ef541-xxxx-xxxx-xxxx-0255ac1001b7", Injection: injectionClusters, Installation: installationClusters, }, } extendParamsSpec := &model.MeshExtendParams{ Clusters: listClustersExtendParams, } specbody := &model.MeshSpec{ Type: model.GetMeshSpecTypeEnum().IN_CLUSTER, Version: "1.18.7-r5", ExtendParams: extendParamsSpec, Config: configSpec, } metadatabody := &model.MeshMetadata{ Name: "mesh-test-api", } request.Body = &model.Mesh{ Spec: specbody, Metadata: metadatabody, Kind: "Mesh", ApiVersion: "v1", } response, err := client.CreateMesh(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
|
状态码 |
描述 |
|---|---|
|
201 |
表示创建网格任务下发成功,开始创建网格 |
|
400 |
用户提供的网格创建参数有问题,未通过校验 |
|
409 |
需要创建的网格与现有网格冲突 |
|
500 |
创建过程中出现问题 |
错误码
请参见错误码。