We can use Mesos + Marathon combo to run containers in a fault tolerant manner. In this post, we would introduce mesos-dns, a service discovery mechanism based on DNS.

enter image description here

Mesos-DNS talks to Mesos master and fetch the information about applications that are launched by various frameworks, like Marathon. It provides an endpoint like myapp.marathon.mesos for the applications or Docker containers that are running using Marathon. Mesos-DNS is simple and does not run as cluster. Ideally, Mesos-DNS should be launched by a framework such as Marathon to ensure high availability. Mesos-DNS is stateless. If it dies, upon restart, it just fetches latest data from the Mesos master. However, if a running Mesos-DNS instance is not able to reach Mesos master, it will continue to serve old data.

How to Setup Mesos-DNS?

Mesos-DNS is distributed as binary from their release page. We need to download it and set executable permission on the binary. Once we are done with that. We need to write a configuration file. A full list of the parameters can be found from Mesos-DNS documentation. We are going to use minimal one from the documentation and edit it to set the IP addresses of our Zookeeper and Mesos master.

  "zk": "zk://",
  "masters": [""],
  "refreshSeconds": 60,
  "ttl": 60,
  "domain": "mesos",
  "port": 53,
  "resolvers": [""],
  "timeout": 5, 
  "httpon": true,
  "dnson": true,
  "httpport": 8123,
  "externalon": true,
  "listener": "",
  "SOAMname": "ns1.mesos",
  "SOARname": "root.ns1.mesos",
  "SOARefresh": 60,
  "SOARetry":   600,
  "SOAExpire":  86400,
  "SOAMinttl": 60,
  "IPSources": ["netinfo", "mesos", "host"]

Once we have written the config to a file, we can start Mesos-DNS by following command:

mesos-dns -config=config.json

Now we have to change the DNS on our machine to use the IP address of Mesos-DNS. For this, edit /etc/resolv.conf appropriately. Any app running on marathon can be reached by using name like <app_id>.marathon.mesosinstead of individual IP addresses. This is particularly useful if there are multiple Docker containers as part of the Marathon app. Mesos-DNS provides a simple DNS round-robin load balancing.

Next Post Previous Post