The NATS Helm charts can be used to deploy a StatefulSet of NATS servers using Helm templates which are easy to extend. Using Helm3 you can add the NATS Helm repo as follows:
nats:# The number of connect attempts against discovered routes.connectRetries:30# How many seconds should pass before sending a PING# to a client that has no activity.pingInterval:# Server settings.limits:maxConnections:maxSubscriptions:maxControlLine:maxPayload:writeDeadline:maxPending:maxPings:lameDuckDuration:# Number of seconds to wait for client connections to end after the pod termination is requestedterminationGracePeriodSeconds:60
Logging
Note: It is not recommended to enable trace or debug in production since enabling it will significantly degrade performance.
In case of both external access and advertisements being enabled, an initializer container will be used to gather the public IPs. This container will be required to have enough RBAC policy to be able to make a look up of the public IP of the node where it is running.
For example, to set up external access for a cluster and advertise the public IP to clients:
nats:# Toggle whether to enable external access.# This binds a host port for clients, gateways and leafnodes.externalAccess:true# Toggle to disable client advertisements (connect_urls),# in case of running behind a load balancer (which is not recommended)# it might be required to disable advertisements.advertise:true# In case both external access and advertise are enabled# then a service account would be required to be able to# gather the public IP from a node.serviceAccount:"nats-server"
Where the service account named nats-server has the following RBAC policy for example:
When using a load balancer for external access, it is recommended to disable advertisement so that internal IPs from the NATS Servers are not advertised to the clients connecting through the load balancer.
gateway:enabled:falsename:'default'############################## ## List of remote gateways ## ############################### gateways:# - name: other# url: nats://my-gateway-url:7522######################## ## TLS Configuration ## ######################### # # You can find more on how to setup and trouble shoot TLS connnections at:# # # https://docs.nats.io/running-a-nats-server/configuration/securing_nats/tls## tls:# secret:# name: nats-client-tls# ca: "ca.crt"# cert: "tls.crt"# key: "tls.key"
Auth setup
Auth with a Memory Resolver
auth:enabled:true# Reference to the Operator JWT.operatorjwt:configMap:name:operator-jwtkey:KO.jwt# Public key of the System AccountsystemAccount:resolver:############################# ## Memory resolver settings ## ###############################type:memory# # Use a configmap reference which will be mounted# into the container.# configMap:name:nats-accountskey:resolver.conf
Auth using an Account Server Resolver
auth:enabled:true# Reference to the Operator JWT.operatorjwt:configMap:name:operator-jwtkey:KO.jwt# Public key of the System AccountsystemAccount:resolver:########################### ## URL resolver settings ## ###########################type:URLurl:"http://nats-account-server:9090/jwt/v1/accounts/"
JetStream
Setting up Memory and File Storage
File Storage is always recommended, since JetStream's RAFT Meta Group will be persisted to file storage. The Storage Class used should be block storage. NFS is not recommended.
nats:image:nats:alpinejetstream:enabled:truememStorage:enabled:truesize:2GifileStorage:enabled:truesize:10Gi# storageClassName: gp2 # NOTE: AWS setup but customize as needed for your infra.
Using with an existing PersistentVolumeClaim
For example, given the following PersistentVolumeClaim:
nats:image:nats:alpinejetstream:enabled:truememStorage:enabled:truesize:"2Gi"fileStorage:enabled:truesize:"1Gi"storageDirectory:/data/storageClassName:defaultcluster:enabled:true# Cluster name is required, by default will be release name.# name: "nats"replicas:3
Misc
NATS Box
A lightweight container with NATS and NATS Streaming utilities deployed along the cluster to confirm the setup. You can find the image at: https://github.com/nats-io/nats-box
You can enable Prometheus operator ServiceMonitor:
exporter:# You have to enable exporter firstenabled:trueserviceMonitor:enabled:true## Specify the namespace where Prometheus Operator is running# namespace: monitoring# ...
Pod Customizations
Security Context
# Toggle whether to use setup a Pod Security Context# ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/securityContext:fsGroup:1000runAsUser:1000runAsNonRoot:true