New to mesos/marathon. How to deploy a new self de

2019-06-06 04:53发布

问题:

I am new to mesos and marathon.

I have a set up where in one docker is self defined and another is mysql server instance. These two are linked and pass information. How do I deploy this on mesos? I am using a single node master and slave set up currently.

回答1:

To link your Docker containers use Mesos-DNS. I'm using Playa Mesos in the following to explain the setup.

Setting up Mesos-DNS on Playa is straightforward: use the mesosphere/mesos-dns image and deploy it on Marathon using the following app spec:

{
"id": "mesos-dns",
"instances": 1,
"cpus": 1,
"mem": 512,
"cmd": "/mesos-dns -config=/config.json",
"container": {
  "type": "DOCKER",
  "docker": {
    "image": "mesosphere/mesos-dns:latest",
    "network": "HOST"
 },
 "volumes": [
      {
        "containerPath": "/config.json",
        "hostPath": "/etc/mesos-dns/config.js",
        "mode": "RW"
      }
    ]
  }
}

With the following config.js:

{
 "zk": "zk://127.0.0.1:2181/mesos",
 "refreshSeconds": 60,
 "ttl": 60,
 "domain": "mesos",
 "port": 53,
 "resolvers": ["10.0.2.3"],
 "timeout": 5,
 "email": "root.mesos-dns.mesos"
}

Also, make sure that the resolv.conf has the right entry in first position:

$ cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.0.1
nameserver 10.0.2.3
search net

You can then dynamically discover your service (on the Vagrant box) as so:

dig _$APPID._tcp.marathon.mesos SRV

Where $APPID is the identifier you used to deploy your custom Docker image. The above command will tell you the IP and the port Marathon has assigned to your app. You can alternatively use the Mesos-DNS HTTP API for service discovery.

Note 1: the DCOS comes with Mesos-DNS pre-installed, so you can directly use it for service discovery.

Note 2: if you run into the issue that your app doesn't understand SRV records you can try this workaround: https://github.com/the-tetanus-clinic/srv-shim



回答2:

The official Marathon documentation says that arbitrary docker commands are allowed in the parameters object (bottom of the doc page), so you could probably use that to connect them.

Alternatively Mesos-DNS seems to be a solution. The first solution should fail as soon as you move from a single host to multiple hosts and your single containers get scheduled to different hosts.

Note: I'm not very experienced with docker either, but these seem to be the only options I could find. However, integrating Docker into Mesos is an ongoing process and integrating Docker Swarm into Mesos is currently work in progress afaik, so these problems will probably we solved in the (hopefully near) future.