Basic NATS and NATS Streaming Setup

Minimal NATS Setup

To try NATS with the minimal number of components, you can start with the following:
1
# Single server NATS
2
kubectl apply -f https://raw.githubusercontent.com/nats-io/k8s/master/nats-server/single-server-nats.yml
Copied!
This will setup:
  • A statefulset with a single NATS server (no auth nor TLS)
  • A nats headless service to which you can connect
Next, try using nats CLI Tool to connect to the nats service to confirm that you have setup your NATS servers correctly.
In one window listen on the subject 'nats'
1
# Send message to NATS
2
nats sub nats hello
Copied!
In another window publish a message on the subject 'nats'
1
nats pub -s nats hello world
Copied!
You should receive that message on the nats sub window

HA Setup Using StatefulSets

In order to have higher availability you can setup NATS servers to run in clustering mode. The following commands will setup a 3 node NATS cluster. Note, you will need more than one node available in your Kubernetes cluster in order for this to work, so in case of deploying onto minikube or docker desktop, please try the single node installer instead.
1
# Create NATS cluster
2
kubectl apply -f https://raw.githubusercontent.com/nats-io/k8s/master/nats-server/simple-nats.yml
Copied!

Using Helm Charts

Using Helm Charts is now the recommended way to deploy NATS servers over Kubernetes
Location of the officially supported Helm:
Last modified 10d ago
Export as PDF
Copy link
Edit on GitHub