Introduction

In this section, you can find several examples of how to deploy NATS and other tools from the NATS ecosystem on Kubernetes.

Running NATS on K8S

Getting started

The fastest and easiest way to get started is to use NATS Helm Charts.

  1. helm repo add nats https://nats-io.github.io/k8s/helm/charts/
  2. helm install my-nats nats/nats

This will install NATS Server in basic setup with NATS box utility container that can be used as a simple way to interact with the server using nats and nsc CLI tools preinstalled.

In case you don’t have a cluster already, you can find some notes on how to create a small cluster using one of the hosted Kubernetes providers here.

To check if NATS is reacheable from within the cluster connect to NATS box

  1. kubectl exec -n default -it deployment/my-nats-box -- /bin/sh -l

and try subscribing and publishing

  1. nats-box:~# nats-sub test &
  2. nats-box:~# nats-pub test hi

If you’re seeing the messages, all went well and you have successfully installed NATS.

Now, let’s discover some more advanced options.

NATS HA setup

To setup your cluster in HA manner, you need to customize NATS Helm charts. Fortunately, values.yaml have most of the features available as easy values customization and there should be no need to manually tweak the templates.

One way to do it is to create your own .yaml file with changed only values:

  1. cluster:
  2. enabled: true
  3. replicas: 3

and run

  1. helm install nats nats/nats --values ha.yaml

JetSteam

Similarly to HA, enabling JetStream requires changing few values:

  1. nats:
  2. jetstream:
  3. enabled: true
  4. memStorage:
  5. enabled: true
  6. size: 2Gi
  7. fileStorage:
  8. enabled: true
  9. size: 1Gi
  10. storageDirectory: /data/

For more examples, including TLS, Auth, external access, leaf nodes and gateways please check Advanced Helm chart examples