This is a Google Compute Engine (GCE) clustering strategy for libcluster. It currently supports identifying nodes based on compute engine labels.
Add :libcluster_gce
to your project's mix dependencies.
def deps do
[
{:libcluster_gce, "~> 0.0.1"}
]
end
libcluster_gce
requires Elixir 1.11+ & Erlang/OTP 22+
Clustering will only apply to nodes that are accessible via the GCP internal DNS. If this doesn't fit your deployment strategy, please open a Github issue describing your deployment configuration.
To cluster an application running in Google Compute Engine, define a topology for libcluster
.
# config.exs
config :libcluster,
topologies: [
my_app: [
strategy: ClusterGCE.Strategy.Labels,
config: [
project: "my-project",
labels: %{
"env" => "prod"
}
]
]
]
Make sure a cluster supervisor is part of your application.
defmodule MyApp.App do
use Application
def start(_type, _args) do
topologies = Application.get_env(:libcluster, :topologies)
children = [
{Cluster.Supervisor, [topologies, [name: MyApp.ClusterSupervisor]]},
# ...
]
Supervisor.start_link(children, strategy: :one_for_one, name: MyApp.Supervisor)
end
end
Update your release's vm.args
file to include the following lines.
## Name of the node
-name <%= release_name%>@${GOOGLE_COMPUTE_ENGINE_INSTANCE}.${GOOGLE_COMPUTE_ENGINE_ZONE}.c.${GOOGLE_CLOUD_PROJECT}.internal
## Limit distributed erlang ports to a single port
-kernel inet_dist_listen_min 9999
-kernel inet_dist_listen_max 9999
Run your application with the environment variable REPLACE_OS_VARS=true
and forward the following tcp ports:
4369 # epmd
9999 # erlang distribution
Shout out to @alexgaribay for the hard work in libcluster_gae.
- Alex Kwiatkowski - alex+git@fremantle.io
libcluster_gce
is released under the MIT license