zenchild
Libcluster-dynamic-srv - Clustering with SRV and Dynamic Ports with Custom EPMd
Announcing libcluster_dynamic_srv: Dynamic Port Clustering for Elixir
I’ve been working on a way to cluster Elixir nodes in dynamic environments without needing to set static ports. This work was heavily inspired by the Caravan package, but differs in one key way: you don’t need to specify a port in the node name. The port can be completely dynamic and is discovered using DNS SRV records. It also has a libcluster DNS strategy for clustering with the SRV records. It is very similar to the K8s strategy in the core libcluster library, but is a bit more flexible around service naming.
I’m currently using this with Nomad and Consul, and I’ve also created a demo lab that uses Docker + Consul if you want to play around with it.
How It Works
Unlike traditional Elixir clustering approaches that require fixed ports, this library leverages DNS SRV records to discover both the host and port information for each node. This makes it perfect for containerized environments where ports are often dynamically assigned.
Future Possibilities
This approach should also work with Kubernetes, though I’m not as experienced with K8s. If someone is interested in exploring this integration, I’d love any feedback on the approach or contributions to the examples folder!
Cheers,
Dan Wanek
Links
- Library on Hex: libcluster_dynamic_srv | Hex
- Demo Lab: GitHub - ElixirOSS/cluster-lab: A lab for playing with Elixir Clustering - uses libcluster_dynamic_srv
- Nomad Example: Check out the example configuration that demonstrates using Consul Connect to secure node connections with mutual TLS.







