docker 的mesos + marathon编排使用marathon-lb做负载均衡,本次介绍如何在已经搭建好的编排中介入marathon-lb
1、从节点拉取marathon-lb的docker镜像
docker pull mesosphere/marathon-lb
2、在marathon页面上创建marathon-lb application,此处选择json模式
{
"id": "/marathon-lb",
"cmd": null,
"cpus": 1,
"mem": 128,
"disk": 0,
"instances": 1,
"constraints": [
[
"hostname",
"UNIQUE"
]
],
"acceptedResourceRoles": [],
"container": {
"type": "DOCKER",
"docker": {
"forcePullImage": false,
"image": "docker.io/mesosphere/marathon-lb",
"parameters": [],
"privileged": true
},
"volumes": []
},
"portDefinitions": [
{
"port": 10001, #lb服务端口
"name": "default",
"protocol": "tcp"
}
],
"args": [
"sse",
"-m",
"http://10.122.163.241:8080", #maarthon的服务地址
"--group",
"external" #group名称 container中指定名称要和该名称一致
]
}
3、创建Tomcat实例测试marathon-lb的负载均衡,此处也使用json模式
{
"id": "/test-tomcat",
"cmd": null,
"cpus": 0.5,
"mem": 128,
"disk": 0,
"instances": 2,
"acceptedResourceRoles": [
"*"
],
"container": {
"type": "DOCKER",
"docker": {
"forcePullImage": false,
"image": "tomcat:latest",
"parameters": [],
"privileged": false
},
"volumes": [
{
"containerPath": "/usr/local/tomcat/logs",
"hostPath": "/opt/test-tomcat",
"mode": "RW"
}
],
"portMappings": [
{
"containerPort": 8080,
"hostPort": 0,
"labels": {},
"protocol": "tcp",
"servicePort": 10001
}
]
},
"healthChecks": [
{
"gracePeriodSeconds": 300,
"ignoreHttp1xx": false,
"intervalSeconds": 10,
"maxConsecutiveFailures": 3,
"path": "/",
"portIndex": 0,
"protocol": "HTTP",
"ipProtocol": "IPv4",
"timeoutSeconds": 20,
"delaySeconds": 15
}
],
"labels": {
"HAPROXY_GROUP": "external",
"HAPROXY_0_VHOST": "tomcat.marathon.mesos",
"HAPROXY_DEPLOYMENT_ALT_PORT": "10002"
},
"networks": [
{
"mode": "container/bridge"
}
],
"portDefinitions": []
}
image.png
4、测试访问:可以单独进行访问,也可以使用负载均衡访问
使用负载均衡访问示例:marathon-lb 所在IP + "servicePort": 10001
image.png
image.png
网友评论