Cluster.Strategy.Kubernetes.DNSSRV (libcluster v3.3.0) View Source

This clustering strategy works by issuing a SRV query for the kubernetes headless service under which the stateful set containing your nodes is running.

For more information, see the kubernetes stateful-application documentation

  • It will fetch the FQDN of all pods under the headless service and attempt to connect.
  • It will continually monitor and update its connections according to the polling_interval (default 5s)

The application_name is configurable (you may have launched erlang with a different configured name), but will in most cases be the name of your application

An example configuration is below:

config :libcluster,
  topologies: [
    k8s_example: [
      strategy: Elixir.Cluster.Strategy.Kubernetes.DNSSRV,
      config: [
        service: "elixir-plug-poc",
        application_name: "elixir_plug_poc",
        polling_interval: 10_000]]]

An example of how this strategy extracts topology information from DNS follows:

bash-5.0# hostname -f
elixir-plug-poc-1.elixir-plug-poc.default.svc.cluster.local
bash-5.0# dig SRV elixir-plug-poc.default.svc.cluster.local

; <<>> DiG 9.14.3 <<>> SRV elixir-plug-poc.default.svc.cluster.local
;; global options: +cmd
;; Got answer:
;; WARNING: .local is reserved for Multicast DNS
;; You are currently testing what happens when an mDNS query is leaked to DNS
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7169
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 2

;; QUESTION SECTION:
;elixir-plug-poc.default.svc.cluster.local. IN SRV

;; ANSWER SECTION:
elixir-plug-poc.default.svc.cluster.local. 30 IN SRV 10 50 0 elixir-plug-poc-0.elixir-plug-poc.default.svc.cluster.local.
elixir-plug-poc.default.svc.cluster.local. 30 IN SRV 10 50 0 elixir-plug-poc-1.elixir-plug-poc.default.svc.cluster.local.

;; ADDITIONAL SECTION:
elixir-plug-poc-0.elixir-plug-poc.default.svc.cluster.local. 30 IN A 10.1.0.95
elixir-plug-poc-1.elixir-plug-poc.default.svc.cluster.local. 30 IN A 10.1.0.96

;; Query time: 0 msec
;; SERVER: 10.96.0.10#53(10.96.0.10)
;; WHEN: Wed Jul 03 11:55:27 UTC 2019
;; MSG SIZE  rcvd: 167

And here is an example of a corresponding kubernetes statefulset/service definition:

apiVersion: v1
kind: Service
metadata:
  name: elixir-plug-poc
  labels:
    app: elixir-plug-poc
spec:
  ports:
  - port: 4000
    name: web
  clusterIP: None
  selector:
    app: elixir-plug-poc
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: elixir-plug-poc
spec:
  serviceName: "elixir-plug-poc"
  replicas: 2
  selector:
    matchLabels:
      app: elixir-plug-poc
  template:
    metadata:
      labels:
        app: elixir-plug-poc
    spec:
      containers:
      - name: elixir-plug-poc
        image: binarytemple/elixir_plug_poc
        args:
          - foreground
        env:
          - name: ERLANG_COOKIE
            value: "cookie"
        imagePullPolicy: Always
        ports:
        - containerPort: 4000
          name: http
          protocol: TCP

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.