Skip to content

wallyqs/nats.dhall

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nats.dhall

License Version

A Dhall package to setup NATS.io clusters on Kubernetes (via dhall-kubernetes).

Getting started

Simple example of creating a 3 node cluster on the default namespace:

let NATS = env:NATS_PRELUDE ? https://wallyqs.github.io/nats.dhall/package.dhall

let cluster =
      NATS.K8S.Cluster::{
      , name = "my-nats"
      , namespace = "default"
      , image = "nats:latest"
      , size = 3
      , config = NATS.Server.Config::{
        , port = 4222
        }
      }

-- Creates a record with a StatefulSet, ConfigMap and Service
-- which can be used for the base setup of the cluster.
let nats/k8s = NATS.K8S.toK8S cluster

-- Create a List object which can be deployed to K8S.
in  NATS.K8S.toList nats/k8s

Then generate the YAML objects which can be applied via kubectl:

$ dhall-to-yaml --file examples/k8s-cluster.dhall | kubectl apply -f -

statefulset.apps/my-nats created
configmap/my-nats-config created
service/my-nats created

Demo

asciicast

Generating the server configuration

It is also possible to create a sample configuration from the original NATS.Server.Config type as follows:

let NATS = env:NATS_PRELUDE ? https://wallyqs.github.io/nats.dhall/package.dhall

let serverConfig =  NATS.Server.Config::{
     , port = 4222
     , logging = Some NATS.Server.LoggingConfig::{
       , debug = False
       , trace = False
       , logtime = False
     }
     , cluster = Some NATS.Server.ClusterConfig::{=}
    }

let conf = NATS.Server.toConf serverConfig
in NATS.Conf.render conf

License

Unless otherwise noted, the NATS source files are distributed under the Apache Version 2.0 license found in the LICENSE file.