Tyblog | Too Simple To Fail: Marrying Nomad, Caddy, and Wireguard

Informative post. consul-template is powerful.

Worth mentioning Caddy can generate reverse proxy configs dynamically from DNS SRV records, too. This can be made to work with Consul’s DNS server:

*.lab.mysite.com {
    # ...

    map {host}                       {subdomain} {
        ~(.*)\.lab\.mysite\.com$     ${1}       
    }   

    # Proxy services with the 'http-reverse' tag.
    handle {
        reverse_proxy {
            dynamic srv {
                name service.consul
                service {subdomain}
                proto http-reverse
                refresh 10s
            }
        }       
    }   

    handle_errors {
		# Do whatever you want here to return error info to clients
		# when a service is not found, etc.
    }   
}

This config assumes Consul is working as the system’s resolver. A consul agent can be running locally with a recursors config to pass other DNS requests upstream.

This doesn’t allow as much fine tuning as the templating approach, but at least the proto field enables filtering by a service tag.