synadia-server

by Synadia

Helm chartv1.1.10App 1.1.10Verified publisher

A Helm chart for Synadia Server

About this chart

[!WARNING]
Control Plane 1.4.0 introduces native support for nats-server, and synadia-server is now deprecated in favor of nats-server. View the FAQ for more information.


Synadia Server Helm Chart

Accessing the Helm Chart

# add the synadia repo (only needs to be run once)
helm repo add synadia https://synadia-io.github.io/helm-charts

# update the synadia repo index (run to get updated chart versions)
helm repo update synadia

# now you can install the synadia/synadia-server chart
helm upgrade --install nats synadia/synadia-server

Values

There are a handful of explicitly defined options which are documented with comments in the values.yaml file.

Everything in the NATS Config or Kubernetes Resources can be overridden by merge and patch, which is supported for the following values:

keytypeenabled by default
configNATS Configyes
config.clusterNATS Clusterno
config.cluster.tlsNATS TLSno
config.jetstreamNATS JetStreamno
config.jetstream.fileStore.pvck8s PVCyes, when config.jetstream is enabled
config.nats.tlsNATS TLSno
config.leafnodesNATS LeafNodesno
config.leafnodes.tlsNATS TLSno
config.websocketNATS WebSocketno
config.websocket.tlsNATS TLSno
config.websocket.ingressk8s Ingressno
config.mqttNATS MQTTno
config.mqtt.tlsNATS TLSno
config.gatewayNATS Gatewayno
config.gateway.tlsNATS TLSno
config.resolverNATS Resolverno
config.resolver.pvck8s PVCyes, when config.resolver is enabled
containernats k8s Containeryes
promExporterprometheus exporter k8s Containerno
promExporter.podMonitorprometheus PodMonitorno
servicek8s Serviceyes
statefulSetk8s StatefulSetyes
podTemplatek8s PodTemplateyes
headlessServicek8s Serviceyes
configMapk8s ConfiegMapyes
optsSecretk8s Secretyes
natsBox.contexts.defaultNATS Contextyes
natsBox.contexts.[name]NATS Contextno
natsBox.containernats-box k8s Containeryes
natsBox.deploymentk8s Deploymentyes
natsBox.podTemplatek8s PodTemplateyes
natsBox.contextsSecretk8s Secretyes
natsBox.contentsSecretk8s Secretyes

Merge

Merging is performed using the Helm merge function. Example - add NATS accounts and container resources:

config:
  merge:
    accounts:
      A:
        users:
          - { user: a, password: a }
      B:
        users:
          - { user: b, password: b }
natsBox:
  contexts:
    a:
      merge: { user: a, password: a }
    b:
      merge: { user: b, password: b }
  defaultContextName: a

Patch

Patching is performed using JSON Patch. Example - add additional route to end of route list:

config:
  cluster:
    enabled: true
    patch:
      - op: add
        path: /routes/-
        value: nats://demo.nats.io:6222

Common Configurations

Connect to Synadia Control Plane

Provisioning instructions in Synadia Control Plane will provide configuration similar to this:

opts:
  # Synadia Control Plane URL
  url: https://cp.nats.io
  # Synadia Control Plane Token
  token: agt_foobar

JetStream Cluster on 3 separate hosts

config:
  cluster:
    enabled: true
    replicas: 3
  jetstream:
    enabled: true
    fileStore:
      pvc:
        size: 10Gi

podTemplate:
  topologySpreadConstraints:
    kubernetes.io/hostname:
      maxSkew: 1
      whenUnsatisfiable: DoNotSchedule

NATS Container Resources

container:
  env:
    # different from k8s units, suffix must be B, KiB, MiB, GiB, or TiB
    # should be ~90% of memory limit
    GOMEMLIMIT: 7GiB
  merge:
    # recommended limit is at least 2 CPU cores and 8Gi Memory for production JetStream clusters
    resources:
      requests:
        cpu: "2"
        memory: 8Gi
      limits:
        cpu: "2"
        memory: 8Gi

Specify Image Version

container:
  image:
    tag: x.y.z

Operator Mode with NATS Resolver

Provisioning instructions in Synadia Control Plane will provide configuration similar to this:

config:
  resolver:
    enabled: true
    merge:
      type: full
      interval: 2m
      timeout: 1.9s
  merge:
    operator: OPERATOR_JWT
    system_account: SYS_ACCOUNT_ID
    resolver_preload:
      SYS_ACCOUNT_ID: SYS_ACCOUNT_JWT

Accessing NATS

The chart contains 2 services by default, service and headlessService.

service

The service is intended to be accessed by NATS Clients. It is a ClusterIP service by default, however it can easily be changed to a different service type.

The nats, websocket, leafnodes, and mqtt ports will be exposed through this service by default if they are enabled.

Example: change this service type to a LoadBalancer:

service:
  merge:
    spec:
      type: LoadBalancer

headlessService

The headlessService is used for NATS Servers in the Stateful Set to discover one another. It is primarily intended to be used for Cluster Route connections.

TLS Considerations

The TLS Certificate used for Client Connections should have a SAN covering DNS Name that clients access the service at.

The TLS Certificate used for Cluster Route Connections should have a SAN covering the DNS Name that routes access each other on the headlessService at. This is *.<headless-service-name> by default.

Advanced Features

Templating Values

Anything in values.yaml can be templated:

  • maps matching the following syntax will be templated and parsed as YAML:
    $tplYaml: |
      yaml template
    
  • maps matching the follow syntax will be templated, parsed as YAML, and spread into the parent map/slice
    $tplYamlSpread: |
      yaml template
    

Example - change service name:

service:
  name:
    $tplYaml: >-
      {{ include "nats.fullname" . }}-svc

NATS Config Units and Variables

NATS configuration extends JSON, and can represent Units and Variables. They must be wrapped in << >> in order to template correctly. Example:

config:
  merge:
    authorization:
      # variable
      token: << $TOKEN >>
    # units
    max_payload: << 2MB >>

templates to the nats.conf:

{
  "authorization": {
    "token": $TOKEN
  },
  "max_payload": 2MB,
  "port": 4222,
  ...
}

NATS Config Includes

Any NATS Config key ending in $include will be replaced with an include directive. Included files should be in paths relative to /etc/nats-config. Multiple $include keys are supported by using a prefix, and will be sorted alphabetically. Example:

config:
  merge:
    00$include: auth.conf
    01$include: params.conf
configMap:
  merge:
    data:
      auth.conf: |
        accounts: {
          A: {
            users: [
              {user: a, password: a}
            ]
          },
          B: {
            users: [
              {user: b, password: b}
            ]
          },
        }
      params.conf: |
        max_payload: 2MB

templates to the nats.conf:

include auth.conf;
"port": 4222,
...
include params.conf;

Extra Resources

Enables adding additional arbitrary resources. Example - expose WebSocket via VirtualService in Istio:

config:
  websocket:
    enabled: true
extraResources:
  - apiVersion: networking.istio.io/v1beta1
    kind: VirtualService
    metadata:
      namespace:
        $tplYamlSpread: >
          {{ include "nats.metadataNamespace" $ }}
      name:
        $tplYaml: >
          {{ include "nats.fullname" $ | quote }}
      labels:
        $tplYaml: |
          {{ include "nats.labels" $ }}
    spec:
      hosts:
        - demo.nats.io
      gateways:
        - my-gateway
      http:
        - name: default
          match:
            - name: root
              uri:
                exact: /
          route:
            - destination:
                host:
                  $tplYaml: >
                    {{ .Values.service.name | quote }}
                port:
                  number:
                    $tplYaml: 

Deploy synadia-server with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has synadia-server on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartsynadia-server is pinned at v1.1.10 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply