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

带有多个容器的 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. },
  69. "killSelection": "Youngest_First",
  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 声明端口 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 将根据 <container_ip>:80 执行 HTTP 请求。如果 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. "endpoints": [
  51. {
  52. "name": "http-endpoint",
  53. "containerPort": 80,
  54. "hostPort": 0,
  55. "protocol": [ "HTTP" ],
  56. "labels": {}
  57. }
  58. ],
  59. "image": {
  60. "id": "nginx:latest",
  61. "kind": "DOCKER",
  62. "forcePull": false
  63. },
  64. "environment": {
  65. "XPS1": "Test"
  66. },
  67. "user": "root",
  68. "healthCheck": {
  69. "gracePeriodSeconds": 30,
  70. "intervalSeconds": 5,
  71. "maxConsecutiveFailures": 3,
  72. "timeoutSeconds": 4,
  73. "delaySeconds": 2,
  74. "http": {
  75. "path": "/",
  76. "scheme": "HTTP",
  77. "endpoint": "http-endpoint"
  78. }
  79. },
  80. "volumeMounts": [
  81. {
  82. "name": "etc",
  83. "mountPath": "/mnt/etc",
  84. "readOnly": true
  85. }
  86. ],
  87. "artifacts": [
  88. {
  89. "uri": "https://ftp.gnu.org/gnu/glibc/glibc-2.25.tar.gz",
  90. "executable": false,
  91. "extract": true,
  92. "cache": true,
  93. "destPath": "glibc-2.25.tar.gz"
  94. }
  95. ],
  96. "labels": {
  97. "owner": "zeus",
  98. "note": "Away from olympus"
  99. },
  100. "lifecycle": {
  101. "killGracePeriodSeconds": 60
  102. }
  103. }