Skip to content

Commit f0733e6

Browse files
authored
Merge pull request #1293 from ripienaar/generate_k8s
Adds a "server generate" bundle for kubernetes clusters
2 parents f4eda5b + 2ca0945 commit f0733e6

File tree

6 files changed

+110
-2
lines changed

6 files changed

+110
-2
lines changed

cli/server_generate.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 The NATS Authors
1+
// Copyright 2024-2025 The NATS Authors
22
// Licensed under the Apache License, Version 2.0 (the "License");
33
// you may not use this file except in compliance with the License.
44
// You may obtain a copy of the License at
@@ -113,6 +113,7 @@ func (c *serverGenerateCmd) pickEmbedded() error {
113113
list := map[string]string{
114114
"Development Super Cluster using Docker Compose": "fs:///natsbuilder",
115115
"'nats auth' managed NATS Server configuration": "fs:///operator",
116+
"'nats auth' managed NATS Cluster in Kubernetes": "fs:///operatork8s",
116117
"Synadia Cloud Leafnode Configuration": "fs:///ngsleafnodeconfig",
117118
}
118119

cli/server_mapping_command.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020-2024 The NATS Authors
1+
// Copyright 2020-2025 The NATS Authors
22
// Licensed under the Apache License, Version 2.0 (the "License");
33
// you may not use this file except in compliance with the License.
44
// You may obtain a copy of the License at
@@ -80,6 +80,8 @@ func (c *SrvMappingCmd) mappingAction(_ *fisk.ParseContext) error {
8080

8181
fmt.Println("Enter subjects to test, empty subject terminates.")
8282
fmt.Println()
83+
fmt.Println("NOTE: This only tests mappings, it does not add them to the server")
84+
fmt.Println()
8385

8486
for {
8587
c.subj = ""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
description: Generates configuration for an operator based NATS Server managed by Kubernetes
2+
contact: https://github.com/nats-io/natscli/issues
3+
source: https://github.com/nats-io/natscli/
4+
version: 0.0.1
5+
requires:
6+
operator: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: nats-server.conf
2+
description: |
3+
Operator Managed NATS Server for Kubernetes
4+
5+
This will guide you through a series of question to create a NATS Cluster
6+
configuration managed by a NATS Operator using the nats Helm Chart.
7+
8+
To use this an Operator should have been created using the "nats auth" command.
9+
10+
For more information about Decentralized Authentication please read:
11+
12+
https://docs.nats.io/running-a-nats-service/configuration/securing_nats/auth_intro/jwt
13+
14+
For more information about the Helm chart please read:
15+
16+
https://github.com/nats-io/k8s/tree/main/helm/charts/nats
17+
18+
Deploy the resulting Cluster using helm:
19+
20+
helm repo add nats https://nats-io.github.io/k8s/helm/charts/
21+
helm upgrade --install nats nats/nats -f values.yaml
22+
23+
To access the cluster you can use kubectl:
24+
25+
kubectl port-forward service/nats 4222
26+
27+
Once set up you can create credentials and push your accounts.
28+
29+
properties:
30+
- name: replicas
31+
description: How many server pods to start
32+
type: integer
33+
default: "3"
34+
35+
- name: streams
36+
description: Enables JetStream in the cluster
37+
type: bool
38+
default: "true"
39+
40+
- name: jetstream
41+
description: |
42+
JetStream configuration
43+
44+
We will now configure the NATS JetStream persistence layer. Setting the limits
45+
to -1 means a dynamic value will be chosen by the server at start. We strongly
46+
suggest setting specific limits.
47+
48+
See https://docs.nats.io/nats-concepts/jetstream for more information
49+
conditional: "input.streams == true"
50+
properties:
51+
- name: storage
52+
description: The maximum amount of PVC resources to allocate
53+
help: Valid values look like '10Gi'
54+
default: "10Gi"
55+
56+
- name: resolver
57+
description: |
58+
NATS Resolver Configuration
59+
60+
We will now configure where the NATS Server will store account JWT files.
61+
JWT files are pushed to the server using 'nats auth account push' and
62+
describe the full configuration for each account.
63+
64+
Every server in a cluster needs a resolver configuration.
65+
properties:
66+
- name: allow_delete
67+
description: Should the server allow accounts to be deleted
68+
default: "true"
69+
type: bool
70+
- name: limit
71+
description: The maximum amount of accounts to allow
72+
default: "1000"
73+
type: integer
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
natsBox:
2+
enabled: false
3+
4+
config:
5+
cluster:
6+
enabled: true
7+
replicas: {{ .replicas }}
8+
resolver:
9+
enabled: true
10+
merge:
11+
type: full
12+
interval: 2m
13+
timeout: 1.9s
14+
{{ if .jetstream }}
15+
jetstream:
16+
enabled: true
17+
fileStore:
18+
pvc:
19+
size: {{ .jetstream.storage }}
20+
{{ end }}
21+
merge:
22+
operator: {{ .Requirements.Operator.JWT }}
23+
system_account: {{ .Requirements.Operator.SystemAccount.Subject }}
24+
resolver_preload:
25+
SYS_ACCOUNT_ID: {{ .Requirements.Operator.SystemAccount.JWT }}

0 commit comments

Comments
 (0)