Create a NATS Cluster
Deploy a fully managed NATS cluster for your messaging needs.
Prerequisites
Before creating a NATS cluster, ensure you have:
- An active SailOps account
- A project created in your organization
- Appropriate permissions (Owner, Maintainer, or Developer role)
Creating a Cluster
Step 1: Navigate to Services
- Log in to your SailOps dashboard
- Select your project from the sidebar
- Click Services in the navigation
Step 2: Create a NATS Cluster
Click Create Service and select NATS to open the creation form.
Step 3: Configure Basic Settings
Cluster Name
Enter a unique name for your cluster:
- Must start with a lowercase letter
- Can contain lowercase letters, numbers, and hyphens
- Must end with a letter or number
- Cannot be changed after creation
Examples: my-nats, production-mq, events-cluster
NATS Version
Select the NATS version:
| Version | Recommendation |
|---|---|
| 2.10 | Stable, well-tested |
| 2.11 | Latest stable |
| 2.12 | Newest features |
Step 4: Configure Resources
Compute Class
Choose based on your workload:
| Class | Best For |
|---|---|
| Eco | Development, testing, low-traffic |
| Standard | Production workloads |
| Production | Critical systems, guaranteed resources |
Flavor
Select the resource allocation. Resources vary by compute class:
Eco Class (1:2 ratio)
| Flavor | CPU | Memory | Recommended For |
|---|---|---|---|
| Small | 0.5 | 1 Gi | Development |
| Medium | 1 | 2 Gi | Testing |
| Large | 2 | 4 Gi | Low-traffic production |
| XLarge | 3 | 6 Gi | Medium workloads |
Standard Class (1:4 ratio)
| Flavor | CPU | Memory | Recommended For |
|---|---|---|---|
| Small | 1 | 4 Gi | Development |
| Medium | 2 | 8 Gi | Production |
| Large | 4 | 16 Gi | High throughput |
| XLarge | 15 | 58 Gi | Enterprise scale |
Production Class (1:4 ratio)
| Flavor | CPU | Memory | Recommended For |
|---|---|---|---|
| Small | 1 | 4 Gi | Critical development |
| Medium | 2 | 8 Gi | Production |
| Large | 4 | 16 Gi | High throughput |
| XLarge | 6 | 28 Gi | Mission critical |
Replicas
Configure cluster size:
| Replicas | Description |
|---|---|
| 1 | Single node, development only |
| 3 | High availability (recommended) |
| 5 | Enhanced fault tolerance |
| 7 | Maximum fault tolerance |
Always use 3 or more replicas for production deployments to ensure high availability.
Step 5: Enable JetStream
JetStream provides persistence capabilities:
- Streams - Persistent message storage
- Key-Value - Distributed configuration
- Object Store - Large file storage
JetStream is disabled by default. Enable it if you need persistent messaging, key-value stores, or object storage. For pure pub/sub without persistence, you can leave it disabled.
Step 6: Review and Create
- Review your configuration
- Click Create Cluster
- Wait for the cluster to become ready (typically 1-2 minutes)
Cluster Detail Tabs
Once created, your NATS cluster detail view has the following tabs:
| Tab | Description |
|---|---|
| Overview | Status, connection information, configuration summary |
| Users | Create and manage NATS users and their permissions |
| JetStream | Manage streams, consumers, key-value stores, and object stores (visible when JetStream is enabled) |
| Logs | Real-time and historical cluster logs |
| Observability | Connection, message, and resource usage metrics |
Connection Information
Once your cluster is ready, you'll see connection details:
Internal Connection
For containers in the same project:
nats://{cluster-name}.{namespace}:4222
Example:
nats://my-nats.my-project-abc123:4222
Connection Code Examples
Node.js
import { connect } from 'nats';
const nc = await connect({
servers: 'nats://my-nats.my-project-abc123:4222'
});
// Publish a message
await nc.publish('events.user.signup', JSON.stringify({ userId: '123' }));
// Subscribe to messages
const sub = nc.subscribe('events.user.*');
for await (const msg of sub) {
console.log(`Received: ${msg.data}`);
}
Go
import "github.com/nats-io/nats.go"
nc, err := nats.Connect("nats://my-nats.my-project-abc123:4222")
if err != nil {
log.Fatal(err)
}
defer nc.Close()
// Publish a message
nc.Publish("events.user.signup", []byte(`{"userId":"123"}`))
// Subscribe to messages
nc.Subscribe("events.user.*", func(m *nats.Msg) {
fmt.Printf("Received: %s\n", string(m.Data))
})
Python
import asyncio
import nats
async def main():
nc = await nats.connect("nats://my-nats.my-project-abc123:4222")
# Publish a message
await nc.publish("events.user.signup", b'{"userId":"123"}')
# Subscribe to messages
async def message_handler(msg):
print(f"Received: {msg.data.decode()}")
await nc.subscribe("events.user.*", cb=message_handler)
asyncio.run(main())
Post-Creation Tasks
After creating your cluster, consider:
1. Create Streams
If using JetStream, create streams for persistent messaging:
- Go to your cluster details
- Click the JetStream tab
- Click Create Stream
- Configure subjects and retention
2. Set Up Key-Value Stores
For distributed configuration:
- Go to the Key-Value section
- Click Create KV Store
- Configure storage and history
3. Configure Monitoring
Set up alerts for:
- Connection count thresholds
- Message rate anomalies
- Consumer lag
4. Update Your Application
Add the NATS connection string to your application's environment variables.
Scaling Your Cluster
Vertical Scaling
Increase resources by:
- Go to cluster settings
- Click Update
- Select a larger flavor
- Apply changes (rolling update)
Horizontal Scaling (Replicas)
Increase replicas for:
- Higher availability
- Better fault tolerance
- Improved performance
Reducing replicas may cause data loss in JetStream. Always increase replicas, don't decrease in production.
Troubleshooting
Cluster Not Ready
If the cluster stays in "Creating" state:
- Check project resource quotas
- Verify network configuration
- Contact support if issues persist
Connection Refused
If clients can't connect:
- Verify the connection string
- Check if the cluster is running
- Ensure containers are in the same project
- Check network policies
Authentication Errors
If authentication fails:
- Verify credentials are correct
- Check if password was set during creation
- Reset password if needed