Skip to content

Instantly share code, notes, and snippets.

View chiragtoor's full-sized avatar

Chirag Singh Toor chiragtoor

View GitHub Profile
defmodule LibCluster.LocalStrategy do
# this defines a strategy used in our local dev environment
# assuming a list of Nodes is defined in the runtime environment,
# we use that to connect our cluster
use Cluster.Strategy
alias Cluster.Strategy.State
def start_link([%State{} = state]) do
case System.get_env("NODES") do
node_binary_list when is_binary(node_binary_list) ->
use Mix.Config
config :libcluster,
topologies: [
example: [
strategy: LibCluster.LocalStrategy
]
]
use Mix.Config
config :libcluster,
topologies: []
use Mix.Config
config :libcluster,
topologies: [
k8s_example: [
strategy: Elixir.Cluster.Strategy.Kubernetes.DNS,
config: [
service: "excluster-service-headless",
application_name: "ex_cluster",
polling_interval: 3_000
# ...
# No longer take in NODES from env
# case System.get_env("NODES") do
# nodes when is_binary(nodes) ->
# nodes
# |> String.split(",")
# |> Enum.map(&String.to_atom/1)
# |> Enum.each(&Node.connect/1)
# _ ->
# nil
apiVersion: v1
kind: Service
metadata:
name: excluster-service-headless
spec:
ports:
- port: 8000
selector:
app: ex-cluster
clusterIP: None
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: ex-cluster
spec:
replicas: 2
template:
metadata:
labels:
app: ex-cluster
FROM elixir:1.7
# Install Hex+Rebar
RUN mix local.hex --force && \
mix local.rebar --force
WORKDIR /opt/app
ENV MIX_ENV=prod
# ...
## Name of the node
-name ex_cluster@${MY_POD_IP}
## Cookie for distributed erlang
-setcookie ${NODE_COOKIE}
# ...
# ...
defp deps do
[
{ :horde, "~> 0.3.0" },
# add distillery and libcluster
{ :distillery, "~> 2.0" },
{ :libcluster, "~> 3.0" }
]
end
# ...