Pod 示例

了解字段定义和 Pod 示例

带注释的简单 Pod 定义

这个名为 的 Pod 只有一个容器 simpletask1. 容器展开镜像(python:3.5.2-alpine)并运行命令。

带注释的多个 Pod 及所有参数

下面的示例显示了一个 pod(test-pod),以及三个容器( healthtask1healthtask2、和 clienttask. Pod 使用共享卷和本地 DC/OS 虚拟网络解决方案。

  1. {
  2. "id":"/test-pod",
  3. "labels":{
  4. "pod_label":"pod"
  5. },
  6. "environment":{
  7. "POD_ENV":"pod"
  8. },
  9. "containers":[
  10. {
  11. "name":"healthtask1",
  12. "exec":{
  13. "command":{
  14. "shell":"./read-write-server.py 8080 mount1/test-file.txt"
  15. }
  16. },
  17. "resources":{
  18. "cpus":0.1,
  19. "mem":32,
  20. "disk":32,
  21. "gpus":0
  22. },
  23. "resourceLimits":{
  24. "cpus": "unlimited",
  25. "mem": 1024
  26. },
  27. "endpoints":[
  28. {
  29. "name":"httpendpoint",
  30. "containerPort":8080,
  31. "hostPort":0,
  32. "protocol":[
  33. "tcp"
  34. ],
  35. "labels":{
  36. "ep1_label":"ep1"
  37. }
  38. }
  39. ],
  40. "image":{
  41. "kind":"DOCKER",
  42. "id":"python:3.5.2-alpine"
  43. },
  44. "environment":{
  45. "C1_ENV":"c1"
  46. },
  47. "healthCheck":{
  48. "http":{
  49. "endpoint":"httpendpoint",
  50. "path":"/ping",
  51. "scheme":"HTTP"
  52. },
  53. "gracePeriodSeconds":30,
  54. "intervalSeconds":5,
  55. "maxConsecutiveFailures":3,
  56. "timeoutSeconds":3,
  57. "delaySeconds":2
  58. },
  59. "volumeMounts":[
  60. {
  61. "name":"sharedvolume",
  62. "mountPath":"mount1"
  63. }
  64. ],
  65. "artifacts":[
  66. {
  67. "uri":"https://s3-us-west-2.amazonaws.com/mesos-soak-cluster/read-write-server.py",
  68. "extract":false,
  69. "executable":true,
  70. "cache":true,
  71. "destPath":"read-write-server.py"
  72. }
  73. ],
  74. "labels":{
  75. "c1_label":"c1"
  76. }
  77. },
  78. {
  79. "name":"healthtask2",
  80. "exec":{
  81. "command":{
  82. "shell":"./read-write-server.py 8081 mount2/test-file.txt"
  83. }
  84. },
  85. "resources":{
  86. "cpus":0.1,
  87. "mem":32,
  88. "disk":32,
  89. "gpus":0
  90. },
  91. "endpoints":[
  92. {
  93. "name":"httpendpoint2",
  94. "containerPort":8081,
  95. "hostPort":0,
  96. "protocol":[
  97. "tcp"
  98. ],
  99. "labels":{
  100. "ep2_label":"ep2"
  101. }
  102. }
  103. ],
  104. "image":{
  105. "kind":"DOCKER",
  106. "id":"python:3.5.2-alpine"
  107. },
  108. "environment":{
  109. "C2_ENV":"c2"
  110. },
  111. "healthCheck":{
  112. "http":{
  113. "endpoint":"httpendpoint2",
  114. "path":"/ping",
  115. "scheme":"HTTP"
  116. },
  117. "gracePeriodSeconds":30,
  118. "intervalSeconds":5,
  119. "maxConsecutiveFailures":3,
  120. "timeoutSeconds":3,
  121. "delaySeconds":2
  122. },
  123. {
  124. "name":"sharedvolume",
  125. "mountPath":"mount2"
  126. }
  127. ],
  128. "artifacts":[
  129. {
  130. "uri":"https://s3-us-west-2.amazonaws.com/mesos-soak-cluster/read-write-server.py",
  131. "extract":false,
  132. "executable":true,
  133. "cache":true,
  134. "destPath":"read-write-server.py"
  135. }
  136. ],
  137. "labels":{
  138. "c2_label":"c2"
  139. }
  140. {
  141. "name":"clienttask",
  142. "exec":{
  143. "command":{
  144. "shell":"while true; do sleep 5 && curl -X GET localhost:8080/write && curl -X GET localhost:8081/read; done"
  145. }
  146. },
  147. "resources":{
  148. "cpus":0.1,
  149. "mem":32,
  150. "disk":32,
  151. "gpus":0
  152. },
  153. "endpoints":[
  154. ],
  155. "environment":{
  156. "C3_ENV":"c3"
  157. },
  158. "volumeMounts":[
  159. ],
  160. "artifacts":[
  161. ],
  162. "labels":{
  163. "c3_label":"c3"
  164. }
  165. }
  166. ],
  167. "secrets":{
  168. },
  169. "volumes":[
  170. {
  171. "name":"sharedvolume"
  172. }
  173. ],
  174. "networks":[
  175. {
  176. "name":"dcos",
  177. "mode":"container",
  178. "labels":{
  179. "net_label":"net"
  180. }
  181. }
  182. ],
  183. "scaling":{
  184. "kind":"fixed",
  185. "instances":1,
  186. "maxInstances":null
  187. },
  188. "scheduling":{
  189. "backoff":{
  190. "backoff":1,
  191. "backoffFactor":1.15,
  192. "maxLaunchDelaySeconds":300
  193. },
  194. "upgrade":{
  195. "minimumHealthCapacity":1,
  196. "maximumOverCapacity":1
  197. },
  198. "placement":{
  199. "constraints":[
  200. ],
  201. "acceptedResourceRoles":[
  202. ]
  203. },
  204. "killSelection":"YOUNGEST_FIRST",
  205. "unreachableStrategy":{
  206. "inactiveAfterSeconds":900,
  207. "expungeAfterSeconds":604800
  208. }
  209. },
  210. "executorResources":{
  211. "cpus":0.1,
  212. "mem":32,
  213. "disk":10
  214. }
  215. }

带有多个容器的 Pod

使用临时卷的 Pod

以下 pod 定义指定了称为 v1. 的临时卷。

  1. {
  2. "id": "/with-ephemeral-vol",
  3. "version": "2017-01-03T17:36:39.389Z",
  4. "containers": [
  5. {
  6. "name": "ct1",
  7. "exec": {
  8. "command": {
  9. "shell": "while true; do echo the current time is $(date) > ./jdef-v1/clock; sleep 1; done"
  10. }
  11. },
  12. "resources": {
  13. "cpus": 0.1,
  14. "mem": 32,
  15. "disk": 0,
  16. "gpus": 0
  17. },
  18. "volumeMounts": [
  19. {
  20. "name": "v1",
  21. "mountPath": "jdef-v1"
  22. }
  23. ]
  24. },
  25. {
  26. "name": "ct2",
  27. "exec": {
  28. "command": {
  29. "shell": "while true; do cat ./etc/clock; sleep 1; done"
  30. }
  31. },
  32. "resources": {
  33. "mem": 32,
  34. "disk": 0,
  35. "gpus": 0
  36. },
  37. "volumeMounts": [
  38. {
  39. "name": "v1",
  40. "mountPath": "etc"
  41. }
  42. ]
  43. }
  44. ],
  45. "volumes": [
  46. {
  47. "name": "v1"
  48. }
  49. ],
  50. "networks": [
  51. {
  52. "mode": "host"
  53. }
  54. ],
  55. "scaling": {
  56. "kind": "fixed",
  57. "instances": 1,
  58. "maxInstances": null
  59. },
  60. "scheduling": {
  61. "backoff": {
  62. "backoff": 1,
  63. "backoffFactor": 1.15,
  64. "maxLaunchDelaySeconds": 300
  65. },
  66. "upgrade": {
  67. "minimumHealthCapacity": 1,
  68. "maximumOverCapacity": 1
  69. },
  70. "unreachableStrategy": {
  71. "inactiveAfterSeconds": 900,
  72. "expungeAfterSeconds": 604800
  73. }
  74. },
  75. "executorResources": {
  76. "cpus": 0.1,
  77. "mem": 32,
  78. "disk": 10
  79. }
  80. }

使用持久卷的 Pod

如需查看使用持久卷的 pod 的示例,请参见 创建具有本地持久卷的 pod.

此 pod 声明端口 80 的侦听“web”端点。

  1. {
  2. "id":"/pod-with-endpoint",
  3. "containers":[
  4. {
  5. "name":"simple-docker",
  6. "resources":{
  7. "cpus":1,
  8. "mem":128,
  9. "disk":0,
  10. "gpus":0
  11. },
  12. "image":{
  13. "kind":"DOCKER",
  14. "id":"nginx"
  15. },
  16. "endpoints":[
  17. {
  18. "name":"web",
  19. "containerPort":80,
  20. "protocol":[
  21. "http"
  22. ]
  23. }
  24. ]
  25. }
  26. ],
  27. "networks":[
  28. {
  29. "mode":"container"
  30. }
  31. ]
  32. }

此 pod 添加引用了 web 端点的运行状况检查。Mesos 将根据 执行 HTTP 请求。<container_ip>:80. 如果 Mesos 收到 HTTP 200 响应,则会通过运行状况检查。

完成 Pod

  1. {
  2. "id": "/complete-pod",
  3. "labels": {
  4. "owner": "zeus",
  5. "note": "Away from olympus"
  6. },
  7. "environment": {
  8. "XPS1": "Test"
  9. },
  10. "volumes": [
  11. {
  12. "name": "etc",
  13. "host": "/etc"
  14. }
  15. ],
  16. "networks": [
  17. {
  18. "mode": "container",
  19. "name": "dcos"
  20. }
  21. ],
  22. "scaling": {
  23. "kind": "fixed",
  24. "instances": 1
  25. },
  26. "scheduling": {
  27. "backoff": {
  28. "backoff": 1,
  29. "backoffFactor": 1.15,
  30. "maxLaunchDelaySeconds": 300
  31. },
  32. "upgrade": {
  33. "minimumHealthCapacity": 1,
  34. "maximumOverCapacity": 1
  35. },
  36. "placement": {
  37. "constraints": [],
  38. "acceptedResourceRoles": []
  39. }
  40. },
  41. "containers": [
  42. {
  43. "name": "container1",
  44. "resources": {
  45. "cpus": 1,
  46. "mem": 128,
  47. "disk": 0,
  48. "gpus": 0
  49. },
  50. "resourceLimits": {
  51. "cpus": "unlimited",
  52. "mem": 1024
  53. },
  54. "endpoints": [
  55. {
  56. "name": "http-endpoint",
  57. "containerPort": 80,
  58. "hostPort": 0,
  59. "protocol": [ "HTTP" ],
  60. "labels": {}
  61. }
  62. ],
  63. "image": {
  64. "id": "nginx:latest",
  65. "kind": "DOCKER",
  66. "forcePull": false
  67. },
  68. "environment": {
  69. "XPS1": "Test"
  70. },
  71. "user": "root",
  72. "healthCheck": {
  73. "gracePeriodSeconds": 30,
  74. "intervalSeconds": 5,
  75. "maxConsecutiveFailures": 3,
  76. "timeoutSeconds": 4,
  77. "delaySeconds": 2,
  78. "http": {
  79. "path": "/",
  80. "scheme": "HTTP",
  81. "endpoint": "http-endpoint"
  82. }
  83. },
  84. "volumeMounts": [
  85. {
  86. "name": "etc",
  87. "mountPath": "/mnt/etc",
  88. "readOnly": true
  89. }
  90. ],
  91. "artifacts": [
  92. {
  93. "uri": "https://ftp.gnu.org/gnu/glibc/glibc-2.25.tar.gz",
  94. "executable": false,
  95. "extract": true,
  96. "cache": true,
  97. "destPath": "glibc-2.25.tar.gz"
  98. }
  99. ],
  100. "labels": {
  101. "owner": "zeus",
  102. "note": "Away from olympus"
  103. },
  104. "lifecycle": {
  105. "killGracePeriodSeconds": 60
  106. }
  107. }
  108. }