View Source gc_discover_dns_ip (gen_cluster v0.3.0)
Discovery method that takes a host name to query DNS A records for and
uses all the returned hosts as peers to connect or reconnect to. Whether
to use the IP or the hostname associated with each IP result is configured with
the option host_type
which takes ip
or hostname
as values. The default
is ip
which uses the IP as is in the node name. When it
is hostname
each returned IP is passed to inet_res:gethostbyaddr/1
to get a hostname for the address.
Since this is a built-in discovery module it has an alias, dns
, which
can be used in place of the full module name, gc_discovery_dns_ip
. The
alias dns
covers both gc_discover_dns_ip
and gc_discover_dns_srv
.
This method (gc_discover_dns_ip
) is used by default and when the option
record_type => ip
is given.
The name part of the node name to connect to is taken from the current node's name.
The following is an example relying on the alias, dns
, and that record_type
defaults to ip
:
{gen_cluster, [{discovery, {dns, #{domain => "k8s-erlang-cluster.k8s-erlang-cluster"}}}]}
This results in the A records for k8s-erlang-cluster.k8s-erlang-cluster
being queried for on every gen_cluster
refresh interval and it tries to
establish connections to those not already connected to.
To use IPv6 set ipv6
to true
:
{gen_cluster, [{discovery, {dns, #{domain => "k8s-erlang-cluster.k8s-erlang-cluster",
ipv6 => true}}}]}
This results in the AAAA records of k8s-erlang-cluster.k8s-erlang-cluster
being queried for.
Summary
Types
Module options. Takes a domain to query for, an optional host_type
which
can be ip
or hostname
, a boolean ipv6
for whether to query for A
or
AAAA
records and lookup_timeout
which is the time each DNS query can take.
Types
-type options() :: #{domain := gc_discover_dns:dns_name(), host_type => gc_discover_dns:host_type(), ipv6 => boolean(), lookup_timeout => erlang:timeout()}.
Module options. Takes a domain to query for, an optional host_type
which
can be ip
or hostname
, a boolean ipv6
for whether to query for A
or
AAAA
records and lookup_timeout
which is the time each DNS query can take.
Functions
-spec init(options()) -> {ok, #state{node_name :: string(), domain :: gc_discover_dns:dns_name(), host_type :: gc_discover_dns:host_type(), ip_record_type :: gc_discover_dns:ip_record_type(), lookup_timeout :: erlang:timeout()}}.
-spec peers(#state{node_name :: string(), domain :: gc_discover_dns:dns_name(), host_type :: gc_discover_dns:host_type(), ip_record_type :: gc_discover_dns:ip_record_type(), lookup_timeout :: erlang:timeout()}) -> gen_cluster:peers().