Skip to main content
NATS Server can be deployed on Kubernetes using StatefulSets for clustered deployments or standard Deployments for single instances. The official Helm chart simplifies complex deployments.

Quick Start with kubectl

Deploy a simple single-node NATS Server:
This creates a basic NATS deployment with a ClusterIP service.

StatefulSet Deployment

For production deployments with clustering and persistence, use a StatefulSet:
nats-statefulset.yaml
Apply the StatefulSet:

ConfigMap for Configuration

Store NATS configuration in a ConfigMap:
nats-config.yaml
Create the ConfigMap:

Service Definitions

Headless Service for StatefulSet

External Service (LoadBalancer)

Monitoring Service

Helm Chart Deployment

The official NATS Helm chart is the recommended way to deploy NATS on Kubernetes.

Installation

Add the NATS Helm repository:
Install NATS with default settings:

Custom Values

Create a values.yaml file for customization:
values.yaml
Install with custom values:

Helm Chart Repository

The NATS Helm chart is available on ArtifactHub. View all configuration options:

JetStream with Persistent Storage

For JetStream deployments, use PersistentVolumeClaims:

Scaling and High Availability

Horizontal Scaling

Scale the StatefulSet:

Pod Disruption Budget

Ensure availability during maintenance:
nats-pdb.yaml

Anti-Affinity Rules

Distribute pods across nodes:

Monitoring and Health Checks

Liveness Probe

Readiness Probe

Prometheus Metrics

Expose metrics for Prometheus:

RBAC Configuration

Create ServiceAccount and permissions:
nats-rbac.yaml

Upgrading

Rolling Update

Update the image version:

Helm Upgrade

Namespace Isolation

Deploy NATS in a dedicated namespace:

Best Practices

Use StatefulSets

Always use StatefulSets for clustered deployments to maintain stable network identities.

Configure Resource Limits

Set appropriate CPU and memory requests/limits based on your workload.

Enable Persistence

Use PersistentVolumes for JetStream to ensure data durability.

Implement Anti-Affinity

Spread pods across nodes for better fault tolerance.

Troubleshooting

Check Pod Status

View Logs

Check Cluster Formation

Verify Configuration

Next Steps

Configuration

Explore advanced configuration options

Docker Deployment

Learn about Docker-based deployments