https://github.com/moomerman/libcluster_tailscale
A libcluster strategy for discovering and connecting Elixir nodes over Tailscale
https://github.com/moomerman/libcluster_tailscale
Last synced: about 1 year ago
JSON representation
A libcluster strategy for discovering and connecting Elixir nodes over Tailscale
- Host: GitHub
- URL: https://github.com/moomerman/libcluster_tailscale
- Owner: moomerman
- License: mit
- Created: 2023-03-04T17:40:43.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-06T21:28:55.000Z (over 3 years ago)
- Last Synced: 2025-05-03T16:16:36.852Z (about 1 year ago)
- Language: Elixir
- Size: 4.88 KB
- Stars: 79
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# libcluster_tailscale
This library adds a `libcluster` strategy for discovering and connecting Elixir nodes over Tailscale.
See [this blog post](https://www.richardtaylor.dev/articles/globally-distributed-elixir-over-tailscale) for a detailed walkthrough.
## Installation
The package can be installed by adding `libcluster_tailscale` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:libcluster_tailscale, "~> 0.1.0"}
]
end
```
## Config
Configure your `libcluster` topology with the following config.
```elixir
config :libcluster,
topologies: [
tailscale: [
strategy: Cluster.Strategy.Tailscale,
config: [
authkey: "tskey-api-xxx-yyy",
tailnet: "example.com",
hostname: "app.example.com",
appname: "app"
]
]
]
```
## Example Phoenix Application
Let us say we're deploying a phoenix application called `hello`.
When you bring your tailscale service up on your node, provide a `hostname` that is consistent across your cluster and this strategy can then find all the IP addresses on your Tailnet belonging to that service and automatically cluster them together.
```sh
tailscale up --authkey=${TAILSCALE_AUTHKEY} --hostname=hello-app
```
Configure your release to use the tailscale IP address as part of the node name:
```sh
ip=$(tailscale ip --4)
export RELEASE_DISTRIBUTION=name
export RELEASE_NODE=<%= @release.name %>@$ip
```
Then configure your cluster as follows
```elixir
config :libcluster,
topologies: [
tailscale: [
strategy: Cluster.Strategy.Tailscale,
config: [
authkey: "tskey-api-xxx-yyy",
tailnet: "example.com",
hostname: "hello-app",
appname: "hello"
]
]
]
```