Pod 示例
了解字段定义和 Pod 示例
带注释的简单 Pod 定义
这个名为 的 Pod 只有一个容器 simpletask1
。容器展开镜像(python:3.5.2-alpine
)并运行命令。
带注释的多个 Pod 及所有参数
下面的示例显示了一个 pod(test-pod
),以及三个容器( healthtask1
、 healthtask2
、和 clienttask
)。Pod 使用共享卷和本地 DC/OS 虚拟网络解决方案。
{
"id":"/test-pod",
"labels":{
"pod_label":"pod"
},
"environment":{
"POD_ENV":"pod"
},
"containers":[
{
"name":"healthtask1",
"exec":{
"command":{
"shell":"./read-write-server.py 8080 mount1/test-file.txt"
}
},
"resources":{
"cpus":0.1,
"mem":32,
"disk":32,
"gpus":0
},
"endpoints":[
{
"name":"httpendpoint",
"containerPort":8080,
"hostPort":0,
"protocol":[
"tcp"
],
"labels":{
"ep1_label":"ep1"
}
}
],
"image":{
"kind":"DOCKER",
"id":"python:3.5.2-alpine"
},
"environment":{
"C1_ENV":"c1"
},
"healthCheck":{
"http":{
"endpoint":"httpendpoint",
"path":"/ping",
"scheme":"HTTP"
},
"gracePeriodSeconds":30,
"intervalSeconds":5,
"maxConsecutiveFailures":3,
"timeoutSeconds":3,
"delaySeconds":2
},
"volumeMounts":[
{
"name":"sharedvolume",
"mountPath":"mount1"
}
],
"artifacts":[
{
"uri":"https://s3-us-west-2.amazonaws.com/mesos-soak-cluster/read-write-server.py",
"extract":false,
"executable":true,
"cache":true,
"destPath":"read-write-server.py"
}
],
"labels":{
"c1_label":"c1"
}
},
{
"name":"healthtask2",
"exec":{
"command":{
"shell":"./read-write-server.py 8081 mount2/test-file.txt"
}
},
"resources":{
"cpus":0.1,
"mem":32,
"disk":32,
"gpus":0
},
"endpoints":[
{
"name":"httpendpoint2",
"containerPort":8081,
"hostPort":0,
"protocol":[
"tcp"
],
"labels":{
"ep2_label":"ep2"
}
}
],
"image":{
"kind":"DOCKER",
"id":"python:3.5.2-alpine"
},
"environment":{
"C2_ENV":"c2"
},
"healthCheck":{
"http":{
"endpoint":"httpendpoint2",
"path":"/ping",
"scheme":"HTTP"
},
"gracePeriodSeconds":30,
"intervalSeconds":5,
"maxConsecutiveFailures":3,
"timeoutSeconds":3,
"delaySeconds":2
},
"volumeMounts":[
{
"name":"sharedvolume",
"mountPath":"mount2"
],
"artifacts":[
{
"uri":"https://s3-us-west-2.amazonaws.com/mesos-soak-cluster/read-write-server.py",
"extract":false,
"executable":true,
"cache":true,
"destPath":"read-write-server.py"
}
],
"labels":{
"c2_label":"c2"
}
},
"name":"clienttask",
"exec":{
"command":{
"shell":"while true; do sleep 5 && curl -X GET localhost:8080/write && curl -X GET localhost:8081/read; done"
}
},
"resources":{
"cpus":0.1,
"mem":32,
"disk":32,
"gpus":0
},
"endpoints":[
],
"environment":{
"C3_ENV":"c3"
},
"volumeMounts":[
],
"artifacts":[
],
"labels":{
"c3_label":"c3"
}
}
],
"secrets":{
},
"volumes":[
{
"name":"sharedvolume"
}
],
"networks":[
{
"name":"dcos",
"mode":"container",
"labels":{
"net_label":"net"
}
}
],
"scaling":{
"kind":"fixed",
"instances":1,
"maxInstances":null
},
"scheduling":{
"backoff":{
"backoff":1,
"backoffFactor":1.15,
"maxLaunchDelaySeconds":300
},
"upgrade":{
"minimumHealthCapacity":1,
"maximumOverCapacity":1
},
"placement":{
"constraints":[
],
"acceptedResourceRoles":[
]
},
"killSelection":"YOUNGEST_FIRST",
"unreachableStrategy":{
"inactiveAfterSeconds":900,
"expungeAfterSeconds":604800
}
},
"executorResources":{
"cpus":0.1,
"mem":32,
"disk":10
}
}
带有多个容器的 Pod
使用临时卷的 Pod
以下 pod 定义指定了称为 v1
的临时卷。
{
"id": "/with-ephemeral-vol",
"version": "2017-01-03T17:36:39.389Z",
"containers": [
{
"name": "ct1",
"exec": {
"command": {
"shell": "while true; do echo the current time is $(date) > ./jdef-v1/clock; sleep 1; done"
}
},
"resources": {
"cpus": 0.1,
"mem": 32,
"disk": 0,
"gpus": 0
},
"volumeMounts": [
{
"name": "v1",
"mountPath": "jdef-v1"
}
]
},
{
"name": "ct2",
"exec": {
"command": {
"shell": "while true; do cat ./etc/clock; sleep 1; done"
}
},
"resources": {
"mem": 32,
"disk": 0,
"gpus": 0
},
"volumeMounts": [
{
"name": "v1",
"mountPath": "etc"
}
]
}
],
"volumes": [
{
"name": "v1"
}
],
"networks": [
{
"mode": "host"
}
],
"scaling": {
"kind": "fixed",
"instances": 1,
"maxInstances": null
},
"scheduling": {
"backoff": {
"backoff": 1,
"backoffFactor": 1.15,
"maxLaunchDelaySeconds": 300
},
"upgrade": {
"minimumHealthCapacity": 1,
},
"killSelection": "Youngest_First",
"unreachableStrategy": {
"inactiveAfterSeconds": 900,
"expungeAfterSeconds": 604800
}
},
"executorResources": {
"cpus": 0.1,
"mem": 32,
"disk": 10
}
}
使用持久卷的 Pod
如需查看使用持久卷的 pod 的示例,请参见 。
此 pod 声明端口 80 的侦听“web”端点。
{
"id":"/pod-with-endpoint",
"containers":[
{
"name":"simple-docker",
"resources":{
"cpus":1,
"mem":128,
"disk":0,
"gpus":0
},
"image":{
"kind":"DOCKER",
"id":"nginx"
},
"endpoints":[
{
"name":"web",
"containerPort":80,
"protocol":[
"http"
]
}
]
}
],
"networks":[
{
"mode":"container"
}
]
}
此 pod 添加引用了 web
端点的运行状况检查。Mesos 将根据 <container_ip>:80
执行 HTTP 请求。如果 Mesos 收到 HTTP 200 响应,则会通过运行状况检查。
完成 Pod
{
"id": "/complete-pod",
"labels": {
"owner": "zeus",
"note": "Away from olympus"
},
"environment": {
"XPS1": "Test"
},
"volumes": [
{
"name": "etc",
"host": "/etc"
}
],
"networks": [
{
"mode": "container",
"name": "dcos"
}
],
"scaling": {
"kind": "fixed",
"instances": 1
},
"scheduling": {
"backoff": {
"backoff": 1,
"backoffFactor": 1.15,
"maxLaunchDelaySeconds": 300
},
"upgrade": {
"minimumHealthCapacity": 1,
"maximumOverCapacity": 1
},
"placement": {
"constraints": [],
"acceptedResourceRoles": []
}
},
"containers": [
{
"name": "container1",
"resources": {
"cpus": 1,
"mem": 128,
"disk": 0,
"gpus": 0
},
"endpoints": [
{
"name": "http-endpoint",
"containerPort": 80,
"hostPort": 0,
"protocol": [ "HTTP" ],
"labels": {}
}
],
"image": {
"id": "nginx:latest",
"kind": "DOCKER",
"forcePull": false
},
"environment": {
"XPS1": "Test"
},
"user": "root",
"healthCheck": {
"gracePeriodSeconds": 30,
"intervalSeconds": 5,
"maxConsecutiveFailures": 3,
"timeoutSeconds": 4,
"delaySeconds": 2,
"http": {
"path": "/",
"scheme": "HTTP",
"endpoint": "http-endpoint"
}
},
"volumeMounts": [
{
"name": "etc",
"mountPath": "/mnt/etc",
"readOnly": true
}
],
"artifacts": [
{
"uri": "https://ftp.gnu.org/gnu/glibc/glibc-2.25.tar.gz",
"executable": false,
"extract": true,
"cache": true,
"destPath": "glibc-2.25.tar.gz"
}
],
"labels": {
"owner": "zeus",
"note": "Away from olympus"
},
"lifecycle": {
"killGracePeriodSeconds": 60
}
}