Skip to content

djmaze/swarmdns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwarmDNS

A tiny dockerized DNS service for Docker swarm mode. It always returns the IP(s) of all active swarm nodes.

That makes it easy to host an arbitrary number of swarm services on a subdomain. Just add an NS record for the chosen subdomain for every manager node in the swarm.

As the service works on manager nodes only, you should have more than one manager node for fail-safe operation.

Quickstart

$ docker service create --name swarmdns \
                        -p 53:53/udp \
                        --mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock,readonly \
                        --constraint "node.role == manager" \
                        mazzolino/swarmdns
                        --domain swarm.example.com

Alternatively, deploy the service stack definition supplied in this repository:

docker stack deploy --compose-file docker-compose.yml swarmdns

Testing

With a cluster of 3 nodes:

$ docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS
4mqk9wohilllRkj7zppwie18h     swarm3              Ready               Active              Reachable
hhv80nx8r2jadchRohk4h3pfx *   swarm2              Ready               Active              Reachable
xx4zcnjnr80yletg4pnx00b4n     swarm1              Ready               Active              Leader

Here's the output:

$ dig +short foo.swarm.example.com @<IP OF ANY SWARM NODE>
192.168.1.230
192.168.1.231
192.168.1.232
$ dig +short bar.swarm.example.com @<IP OF ANY SWARM NODE>
192.168.1.231
192.168.1.232
192.168.1.230

How it works

SwarmDNS will answer requests for A records only, and only for names in the domains specified at the commandline. It will always return the IP addresses of all active nodes in the swarm, in random order. (The AVAILABILITY column in docker node ls shows which nodes are currently Active.)

The list of active nodes is refreshed once a minute. The TTL of the returned records is also set to 60 seconds.

Options

The domains to return results for need to be specified using the --domain flag (e.g. -domain swarm.example.com).

When given the --log flag, every matching request will be logged to STDOUT. Example:

Request:   172.17.0.1      foo.swarm.example.com.
Request:   172.17.0.1      bar.swarm.example.com.

When using --rate-limit xxx, the number of simultaneous requests being worked on is limited to xxx. That means additional requests being sent in parallel will be delayed.

Development

Prerequisites

  • Docker
  • Docker-Compose

Building

Just run docker-compose build. It builds a docker image mazzolino/swarmdns by default.

Testing

(Only works if your host is a swarm manager node.)

$ docker-compose up -d
$ dig foo.swarm.example.com @localhost

Credits

This is a fork of WildDNS. The code structure was originally adopted from microdns. Thanks!

About

DNS service for Docker swarm mode which always returns the IP(s) of all active swarm nodes

Resources

License

Stars

Watchers

Forks

Packages

No packages published