Skip to content

Instantly share code, notes, and snippets.

@x-ji
Created December 12, 2019 19:14
Show Gist options
  • Save x-ji/556c6ff370e67cdc3244fc558dfaf8ad to your computer and use it in GitHub Desktop.
Save x-ji/556c6ff370e67cdc3244fc558dfaf8ad to your computer and use it in GitHub Desktop.
Markdium-Elixir process orchestration in Kubernetes with libcluster and swarm
### In mix.exs
defp deps do
[
...
{:libcluster, "~> 3.1"},
...
]
end
### In config/prod.exs
config :libcluster,
topologies: [
your_app: [
strategy: Cluster.Strategy.Kubernetes.DNS,
config: [
service: "your-app-headless",
# The one as seen in node name yourapp@
application_name: "yourapp",
polling_interval: 10_000
]
]
]
### In lib/application.ex
def start(_type, _args) do
# List all child processes to be supervised
children =
[
[
{
Cluster.Supervisor,
[
Application.get_env(:libcluster, :topologies),
[name: Yourapp.ClusterSupervisor]
]
}
],
# Start the Ecto repository
Yourapp.Repo,
# Start the endpoint when the application starts
YourappWeb.Endpoint,
]
opts = [strategy: :one_for_one, name: Yourapp.Supervisor]
Supervisor.start_link(children, opts)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment