版本
linkerd 1.0.2
namerd 1.0.2
简要说明
搭建基于dcos的linkerd 和 namerd.
使用demo来源:
linkerd 配置 linkerd-dcos.json
注意:instances是实际dcos集群数量
{ "id": "linkerd", "instances": 15, "cpus": 0.25, "mem": 256.0, "acceptedResourceRoles": ["*", "slave_public"], "constraints": [["hostname", "UNIQUE"]], "container": { "type": "DOCKER", "docker": { "image": "buoyantio/linkerd:1.0.2", "network": "HOST", "privileged": true } }, "healthChecks": [ { "protocol": "HTTP", "portIndex": 0, "path": "/admin/ping" } ], "portDefinitions": [ { "port": 9990, "protocol": "tcp", "name": "admin" }, { "port": 4140, "protocol": "tcp", "name": "proxy" } ], "requirePorts": true, "cmd": "echo \"{\\\"admin\\\":{\\\"port\\\":9990},\\\"telemetry\\\":[{\\\"kind\\\":\\\"io.l5d.prometheus\\\"}],\\\"routers\\\":[{\\\"protocol\\\":\\\"http\\\",\\\"servers\\\":[{\\\"port\\\":4140,\\\"ip\\\":\\\"0.0.0.0\\\"}],\\\"label\\\":\\\"linkerd_proxy\\\",\\\"interpreter\\\":{\\\"kind\\\":\\\"io.l5d.namerd\\\",\\\"dst\\\":\\\"/$/inet/namerd.marathon.mesos/4100\\\"}}]}\" | /io.buoyant/linkerd/1.0.2/bundle-exec -log.level=DEBUG -com.twitter.finagle.tracing.debugTrace=true -- -"}
namerd 配置 namerd-dcos.json
{ "id": "namerd", "instances": 1, "cpus": 0.25, "mem": 256.0, "acceptedResourceRoles": [ "slave_public" ], "constraints": [["hostname", "UNIQUE"]], "container": { "type": "DOCKER", "docker": { "image": "buoyantio/namerd:1.0.2-dcos", "network": "HOST", "privileged": true } }, "healthChecks": [ { "protocol": "HTTP", "portIndex": 0, "path": "/admin/ping" } ], "portDefinitions": [ { "port": 9001, "protocol": "tcp", "name": "admin" }, { "port": 4180, "protocol": "tcp", "name": "http" }, { "port": 4100, "protocol": "tcp", "name": "thrift" } ], "requirePorts":true, "cmd": "echo \"{\\\"admin\\\":{\\\"port\\\":9001},\\\"storage\\\":{\\\"kind\\\":\\\"io.l5d.zk\\\",\\\"zkAddrs\\\":[{\\\"host\\\":\\\"leader.mesos\\\",\\\"port\\\":2181}],\\\"pathPrefix\\\":\\\"/dtabs\\\",\\\"sessionTimeoutMs\\\":10000},\\\"namers\\\":[{\\\"kind\\\":\\\"io.l5d.marathon\\\",\\\"host\\\":\\\"marathon.mesos\\\",\\\"port\\\":8080}],\\\"interfaces\\\":[{\\\"kind\\\":\\\"io.l5d.thriftNameInterpreter\\\",\\\"ip\\\":\\\"0.0.0.0\\\",\\\"port\\\":4100},{\\\"kind\\\":\\\"io.l5d.httpController\\\",\\\"ip\\\":\\\"0.0.0.0\\\",\\\"port\\\":4180}]}\" | /io.buoyant/namerd/1.0.2/dcos-exec -log.level=DEBUG -com.twitter.finagle.tracing.debugTrace=true -- -"}
测试demo webapp.json
{ "id": "webapp", "cmd": "/bin/bash -c 'echo \"webapp\" > hello; python3 -m http.server $PORT0'", "cpus": 0.5, "mem": 64.0, "instances": 2, "container": { "type": "DOCKER", "docker": { "image": "python:3", "network": "BRIDGE", "portMappings": [ { "containerPort": 0, "hostPort": 0, "protocol": "tcp" } ] } }, "healthChecks": [ { "protocol": "HTTP", "portIndex": 0, "path": "/", "gracePeriodSeconds": 5, "intervalSeconds": 20, "maxConsecutiveFailures": 3 } ]}
使用dcos client发布
## 设置dcos地址dcos config set core.dcos_url $dcos_url ##部署dcos marathon app add linkerd-dcos.jsondcos marathon app add namerd-dcos.jsondcos marathon app add webapp.json
测试访问
通过dcos ui查看部署成功后,首先单独访问webapp,成功后再通过linkerd访问.
笔者当时webapp当时访问地址为 , 访问正常.
随机一台linkerd地址为:
webapp为上面测试demo部署在dcos中实例名称,hello为接口地址(具体可看测试demo webapp.json的配置).
两种方式通过linkerd访问
设置http_proxy
http_proxy=http://192.168.3.72:4140/ curl http://webapp/hello
设置header : Host
curl -H "Host: webapp" http://192.168.3.72:4140/hello
访问都返回为 webapp,证明部署成功.