All Products
Search
Document Center

CreateContainerGroupFromTemplate

Last Updated: Aug 15, 2019

You can call this operation to create a container group based on a template.

Request Parameters

Parameter Type Required Description
Action String Yes The operation that you want to perform. Set this parameter to CreateContainerGroupFromTemplate.
Template String Yes The template in the JSON format. For more information about the format, see the following example.

The standard format for the template is as follows.

  1. {
  2. "regionId": "cn-hangzhou",
  3. "ZoneId": "cn-hangzhou-e",
  4. "securityGroupId": "sg-bp118ky5j07tymorgzfhyw",
  5. "vSwitchId": "vsw-bp1jfjsdy54ky7gerhcf8bc",
  6. "resourceGroupId": "rg-hfh4hjf6hdfeur8h9",
  7. "containerGroupName": "template-test",
  8. "instanceType":"ecs.t5-lc1m2.large",
  9. "slsEnable":true,
  10. "resources": {
  11. "cpu": 4.0,
  12. "memory": 8.0
  13. },
  14. "tags":[
  15. {
  16. "key":"createdFrom",
  17. "value":"template"
  18. },
  19. {
  20. "key":"version",
  21. "value":"1.0.4"
  22. }
  23. ],
  24. "spec": {
  25. "initContainers": [
  26. {
  27. "image": "registry-vpc.cn-hangzhou.aliyuncs.com/liumi/busybox:1.0",
  28. "name": "busybox",
  29. "resources": {
  30. "cpu": 1.345,
  31. "memory": 3.674
  32. },
  33. "imagePullPolicy": "Always"
  34. }
  35. ],
  36. "containers": [
  37. {
  38. "image": "registry-vpc.cn-hangzhou.aliyuncs.com/liumi/nginx:alpine",
  39. "name": "nginx",
  40. "imagePullPolicy": "Always",
  41. "resources": {
  42. "cpu": 1.345,
  43. "memory": 3.674
  44. },
  45. "command": [
  46. "/bin/sh"
  47. ],
  48. "args": [
  49. "-c",
  50. "cp -r /pod/data/ /usr/share/"
  51. ],
  52. "volumeMounts": [
  53. {
  54. "readOnly": false,
  55. "mountPath": "/pod/data",
  56. "name": "nfs-volume"
  57. }
  58. ],
  59. "securityContext": {
  60. "readOnlyRootFilesystem": "true",
  61. "capabilities": {
  62. "add": [
  63. "NET_ADMIN"
  64. ]
  65. },
  66. "runAsUser": "1337"
  67. },
  68. "env": [
  69. {
  70. "name": "KUBERNETES_SERVICE_HOST",
  71. "value": "47.xx. 32.xx"
  72. },
  73. {
  74. "name": "KUBERNETES_SERVICE_PORT",
  75. "value": "6443"
  76. },
  77. {
  78. "name": "ECI_IP",
  79. "valueFrom": {
  80. "fieldRef":{
  81. "fieldPath":"status.podIP"
  82. }
  83. }
  84. }
  85. ],
  86. "readinessProbe": {
  87. "tcpSocket": {
  88. "port": "80"
  89. },
  90. "timeoutSeconds": "5",
  91. "initialDelaySeconds": "5",
  92. "periodSeconds": "5",
  93. "successThreshold": "3",
  94. "failureThreshold": "3"
  95. },
  96. "livenessProbe": {
  97. "exec": {
  98. "command": ["cat", "/tmp/healthy"]
  99. },
  100. "timeoutSeconds": "5",
  101. "initialDelaySeconds": "5",
  102. "periodSeconds": "5",
  103. "successThreshold": "1",
  104. "failureThreshold": "3"
  105. },
  106. "ports": [
  107. {
  108. "IpProtocol": "TCP",
  109. "containerPort": "8080"
  110. },
  111. {
  112. "IpProtocol": "TCP",
  113. "containerPort": "80"
  114. }
  115. ]
  116. }
  117. ],
  118. "dnsConfig": {
  119. "searches": [
  120. "c7a1790b3f206498382cbba682c257b0e.svc.cluster.local",
  121. "svc.cluster.local",
  122. "cluster.local"
  123. ]
  124. },
  125. "restartPolicy": "Always",
  126. "volumes": [
  127. {
  128. "nfs": {
  129. "path": "/",
  130. "readOnly" : false,
  131. "server": "0ajddh74a604-jaq68.cn-hangzhou.nas.aliyuncs.com"
  132. },
  133. "name": "nfs-volume"
  134. },
  135. {
  136. "emptyDir": {
  137. "medium": "Memory"
  138. },
  139. "name": "nfs-volume"
  140. },
  141. {
  142. "configFile": {
  143. "defaltMode": xxx,
  144. "items":[
  145. {
  146. "mode": xxx,
  147. "path": "data/test1",
  148. "content": "%8R8T=",
  149. },
  150. {
  151. "mode": xxx,
  152. "path": "data/test2",
  153. "content": "%8R8T=",
  154. }
  155. ]
  156. },
  157. "name": "nfs-volume"
  158. }
  159. ],
  160. "securityContext": {
  161. "sysctls": [
  162. {
  163. "Name":"kernel.shm_rmid_forced",
  164. "Value":"0",
  165. },
  166. {
  167. "Name":"kernel.msgmax",
  168. "Value":"65536"
  169. }
  170. ]
  171. },
  172. "imagePullSecrets": [
  173. {
  174. "userName": "yourusername",
  175. "password": "password123456",
  176. "server": "registry-vpc.cn-shanghai.aliyuncs.com"
  177. }
  178. ]
  179. }
  180. }

The following figure shows the parameters supported by the template.

ECI templates

Response parameters

Parameter Type Description
RequestId String The ID of the request.
ContainerGroupId String The ID of the container group.

When you query the container group, the returned result is the same regardless of whether you create the container group with or without using a template.

Error codes

For more information about errors common to all operations, seeCommon error codes.

HTTP status code Error code Error message Description
400 Account.Arrearage Your account has an outstanding payment. The error message returned because your account has overdue payments.
400 InvalidParameter.CPU.Memory The specified cpu and memory are not allowed The error message returned because the specified combination of vCPUs and memory is invalid. For more information, see ECI specifications.
400 InvalidParameter.DuplicatedName The container group includes volumes with duplicate names. The error message returned because the container group includes containers with duplicate names.
403 OperationDenied.NoStock Sales of this resource are temporarily suspended in the specified region; please try again later. The error message returned because the resource is not available in the specified region. Try again later.
403 OperationDenied.VswZoneMisMatch The specified VSwitchId is not in the specified Zone. The error message returned because the specified VSwitch does not reside in the specified zone.
403 QuotaExceeded %s quota exceeded. The error message returned because the number of container groups created exceeds the upper limit.
403 Zone.NotOnSale The specified zone is not available for purchase. The error message returned because the container group is not available for sale in the specified region.
403 Forbidden.RiskControl This operation has been identified as an abnormal operation and cannot be processed. The error message returned because this operation is abnormal and cannot be processed.
403 Forbidden.SubUser The specified action is not available for you. The error message returned because you are not authorized to perform the specified operation.
403 Forbidden.OnlyForInvitedTest Eci create action is only open to invited users during public beta. The error message returned because only the invited users can create container groups during the beta release.
400 InvalidParameter.DuplicatedVolumeName The container group includes volumes with duplicate names. The error message returned because the container group includes duplicate volume names.
400 IncorrectStatus %s The error message returned because you cannot perform the operation on the resource in the current status.
403 OperationDenied.SecurityGroupMisMatch The specified VSwitchId and SecurityGroupId are not in the same VPC. The error message returned because the specified VSwitchId and SecurityGroupId are not connected to the same VPC.
403 InvalidVSwitchId.IpNotEnough The specified VSwitch does not have enough IP addresses. The error message returned because the specified VSwitch does not have sufficient IP addresses.
403 Forbidden.UserBussinessStatus This operation is not allowed, because you have overdue bills. Pay the overdue bill and try again. The error message returned because this operation is not allowed when you have overdue payments. Pay the overdue bills and try again later.
403 Forbidden.UserNotRealNameAuthentication This operation is not allowed, because you have not passed the real-name verification. The error message returned because you have not passed the real-name authentication and cannot perform the operation.