NATS and Kubernetes
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
Copied!
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
Copied!
and try subscribing and publishing
1
nats-box:~# nats-sub test &
2
nats-box:~# nats-pub test hi
Copied!
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
Copied!
and run
1
helm install nats nats/nats --values ha.yaml
Copied!

JetSteam

Similarly to HA, enabling JetStream requires changing few values:
1
nats:
2
jetstream:
3
enabled: true
4
5
memStorage:
6
enabled: true
7
size: 2Gi
8
9
fileStorage:
10
enabled: true
11
size: 1Gi
12
storageDirectory: /data/
Copied!
For more examples, including TLS, Auth, external access, leaf nodes and gateways please check Advanced Helm chart examples
Export as PDF
Copy link
Edit on GitHub