调用CreateContainerGroupFromTemplate直接通过模板创建ECI实例。

调试

您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。

请求参数

名称 类型 是否必选 示例值 描述
RegionId String cn-hangzhou

实例所属的地域 ID。

Template String {}

模板参数。

Action String CreateContainerGroupFromTemplate

操作接口名。系统规定参数,取值:CreateContainerGroupFromTemplate

ClientToken String 123e4567-xxxx-12d3-xxxx-426655440000

保证请求幂等性。从您的客户端生成一个参数值,确保不同请求间该参数值唯一。只支持ASCII字符,且不能超过64个字符。更多详情,请参阅如何保证幂等性

Template参数标准格式


{
    "regionId": "cn-hangzhou",
    "zoneId": "cn-hangzhou-h",
    "securityGroupId": "sg-bp118ky5j07tymorgzfhyw",
    "vSwitchId": "vsw-bp1jfjsdy54ky7gerhcf8bc",
    "resourceGroupId": "rg-hfh4hjf6hdfeur8h9",
    "containerGroupName": "template-test",
    "instanceType":"ecs.t5-lc1m2.large",
    "slsEnable":true,
    "resources": {
        "cpu": 4.0,
        "memory": 8.0
    },
    "tags":[
        {
            "key":"createdFrom",
            "value":"template"
        },
        {
            "key":"version",
            "value":"1.0.4"
        }
    ],
    "spec": {
        "initContainers": [
            {
                "image": "registry-vpc.cn-hangzhou.aliyuncs.com/liumi/busybox:1.0",
                "name": "busybox",
                "resources": {
                    "cpu": 1.345,
                    "memory": 3.674
                },
                "imagePullPolicy": "Always"
            }
        ],
        "containers": [
            {
                "image": "registry-vpc.cn-hangzhou.aliyuncs.com/liumi/nginx:alpine",
                "name": "nginx",
                "imagePullPolicy": "Always",
                "resources": {
                    "cpu": 1.345,
                    "memory": 3.674
                },
                "command": [
                    "/bin/sh"
                ],
                "args": [
                    "-c",
                    "cp -r /pod/data/ /usr/share/"
                ],
                "volumeMounts": [
                    {
                        "readOnly": false,
                        "mountPath": "/pod/data",
                        "name": "nfs-volume"
                    }
                ],
                "securityContext": {
                    "readOnlyRootFilesystem": "true",
                    "capabilities": {
                        "add": [
                            "NET_ADMIN"
                        ]
                    },
                    "runAsUser": "1337"
                },
                "env": [
                    {
                        "name": "KUBERNETES_SERVICE_HOST",
                        "value": "47.xx.32.xx"
                    },
                    {
                        "name": "KUBERNETES_SERVICE_PORT",
                        "value": "6443"
                    },
                    {
                        "name": "ECI_IP",
                        "valueFrom": {
                            "fieldRef":{
                                "fieldPath":"status.podIP"
                            }
                        }
                    }
                ],
                "readinessProbe": {
                    "tcpSocket": {
                        "port": "80"
                    },
                    "timeoutSeconds": "5",
                    "initialDelaySeconds": "5",
                    "periodSeconds": "5",
                    "successThreshold": "3",
                    "failureThreshold": "3"
                },
                "livenessProbe": {
                    "exec": {
                        "command": ["cat", "/tmp/healthy"]
                    },
                    "timeoutSeconds": "5",
                    "initialDelaySeconds": "5",
                    "periodSeconds": "5",
                    "successThreshold": "1",
                    "failureThreshold": "3"
                },
                "ports": [
                    {
                        "protocol": "TCP",
                        "containerPort": "8080"
                    },
                    {
                        "protocol": "TCP",
                        "containerPort": "80"
                    }
                ]
            }
        ],
        "dnsConfig": {
            "searches": [
                "c7a1790b3f206498382cbba682c257b0e.svc.cluster.local",
                "svc.cluster.local",
                "cluster.local"
            ]
        },
        "restartPolicy": "Always",
        "volumes": [
            {
                "nfs": {
                    "path": "/",
                    "readOnly": false,
                    "server": "0ajddh74a604-jaq68.cn-hangzhou.nas.aliyuncs.com"
                },
                "name": "nfs-volume"
            },
            {
                "emptyDir": {
                    "medium": "Memory"
                },
                "name": "nfs-volume"
            },
            {
                "configFile": {
                    "defaltMode": xxx,
                    "items":[
                        {
                         "mode": xxx,
                            "path": "data/test1",
                         "content": "%8R8T=",   
                        },
                        {
                         "mode": xxx,
                            "path": "data/test2",
                         "content": "%8R8T=",   
                        }  
                    ]
                },
                "name": "nfs-volume"
            }
        ],
        "securityContext": {
            "sysctls": [
                {
                    "Name":"kernel.shm_rmid_forced",
                    "Value":"0"
                },
                {
                   "Name":"kernel.msgmax",
                    "Value":"65536" 
                }
            ]
        },
        "imagePullSecrets": [
            {
                "userName": "yourusername",
                "password": "password123456",
                "server": "registry-vpc.cn-shanghai.aliyuncs.com"
            }
        ]
    }
}

模板目前支持的所有参数如下:!ECI模板

返回数据

名称 类型 示例值 描述
ContainerGroupId String eci-uf6fonnghi50u374a0i4

容器组 ID。

RequestId String 28B583A8-313D-4383-8EA9-B5A9F7E07817

请求ID,唯一标识。

示例

请求示例


http(s)://eci.aliyuncs.com/?Action=CreateContainerGroupFromTemplate
&RegionId=cn-hangzhou
&Template={}
&<公共请求参数>

正常返回示例

XML 格式

<CreateContainerGroupFromTemplateReponse>
      <ContainerGroupId>eci-uf6fonnghi50u374a0i4</ContainerGroupId>
      <RequestId>28B583A8-313D-4383-8EA9-B5A9F7E07817</RequestId>
</CreateContainerGroupFromTemplateReponse>

JSON 格式

{
	"ContainerGroupId":"eci-uf6fonnghi50u374a0i4",
	"RequestId":"28B583A8-313D-4383-8EA9-B5A9F7E07817"
}
说明 : 目前不论是通过原子化API创建还是通过新模板化的API的创建,用户查询接口查询到的结果是一致的。

错误码

HttpCode 错误码 错误信息 描述
403 Throttling.Vcpu.PerDay The maximum number of request for the day has been exceeded. 当天的请求配额已经超出。
403 Zone.NotOnSale The specified zone is not available for purchase. 创建实例的可用区已经关闭售卖,请更换其他可用区。或者无法在该可用区使用指定 VPC 的虚拟交换机。
400 MissingParameter %s 必填参数缺失
409 OperationConflict The request was denied. It conflicts with a previous request. 该请求被禁止,因为与之前的请求冲突
403 OperationDenied.NoStock Sales of this resource are temporarily suspended in the specified region; please try again later. 库存不足,请尝试其它系列或者其它可用区/地域的实例。
403 OperationDenied.SecurityGroupMisMatch The specified VSwitchId and SecurityGroupId are not in the same VPC. 指定的交换机和安全组不在同一个VPC下
403 OperationDenied.SecurityGroupMisMatch The specified VSwitchId and SecurityGroupId are not in the same VPC. 指定的交换机和安全组不在同一个VPC下
403 OperationDenied.VswZoneMisMatch The specified VSwitchId is not in the specified Zone. 指定的交换机不在可用区
403 QuotaExceeded %s quota exceeded. 用户允许创建的实例已经超过限制
400 InvalidParameter %s 不合法的参数
400 InvalidParameter.CPU.Memory The specified cpu and memory are not allowed cpu,mem不符合规格
400 InvalidParameter.DuplicatedName The container group include containers with duplicate names. 容器组内有重复名字的容器。
400 InvalidParameter.DuplicatedName The container group includes volumes with duplicate names. 容器组内有重复名字的数据卷。
400 InvalidParameter.DuplicatedVolumeName The container group includes volumes with duplicate names. 容器组内有重复名字的数据卷。
400 InvalidParameter.LengthExceeded %s List型参数的长度超过规定值
404 InvalidParameter.NotFound %s 参数未找到
400 InvalidParameter.ValueExceeded %s 参数值超过规定范围
403 InvalidVSwitchId.IpNotEnough The specified VSwitch does not have enough IP addresses. 交换机没有足够ip地址
400 InvalidParam.CpuOrMemorySpec The specified specification is invalid. 指定的规格还未开放售卖,不提供价格查询。

访问错误中心查看更多错误码。