# nats

Standalone or clustered NATS messaging server with JetStream persistence

This page is generated from [`kix/packages/experimental/nats`](https://github.com/kix-run/kix/tree/main/kix/packages/experimental/nats).

| | |
| --- | --- |
| Stability | Experimental |
| `package` value | `packages.experimental.nats` |
| Default software version | `2.15.3` |
| Default aliases | `nats` |

## Dependencies

Kix matches each dependency below to another package instance by instance name, alias, or role. To bind a specific instance, set [`deps.<name>`](/docs/reference/instances-and-composition/#deps) in your cluster definition. See [Declaring dependencies](/docs/reference/package-anatomy/#declaring-dependencies) for how required and optional dependencies work.

| Dependency | Requirement |
| --- | --- |
| `natsAuth` | Required |
| `prometheus` | Optional |
| `storageClasses` | Optional |

## Options

### `clustered`

Run a NATS cluster of `replicas` servers (`true`) or one standalone server (`false`). Availability levels do not change `clustered` automatically: Kix rejects `false` at `pod`, `node`, or `zone`, and rejects `true` at `none`. NATS cannot convert a server with stored streams between standalone and clustered modes in place. To migrate an instance with data, back up every stream (`nats stream backup`), delete every stream (`nats stream rm`), delete the StatefulSet when moving from standalone to clustered (its PersistentVolumeClaims stay), change `clustered` and deploy, then restore the streams (`nats stream restore`).

- **Type:** `boolean`
- **Default:** `false`

### `env`

Extra environment variables for the `nats` container. `GOMEMLIMIT` defaults to 80% of `resources.limits.memory`; set `env.GOMEMLIMIT` to override it. Kix rejects `POD_NAME`, `NATS_USER`, `NATS_PASSWORD`, `AUTH_USER`, and `AUTH_PASSWORD`, which this package sets itself.

- **Type:** ``attribute set of (null or string or env var source with `valueFrom`)``
- **Default:** `{ }`

### `healthCheck.enabled`

Run a post-deploy Job that verifies the NATS instance through its client Service. The Job logs in, publishes and reads back a test message, queries JetStream account info when `jetstream.enabled` is `true`, and confirms that unauthenticated connections are rejected.

- **Type:** `boolean`
- **Default:** `true`

### `healthCheck.retryFor`

Seconds the probe keeps re-checking before it gives up, so a target still restarting from the rollout does not fail the deploy. The Job's deadline is sized from it.

- **Type:** `signed integer`
- **Default:** `90`

### `image`

Container image for `nats-server`.

- **Type:** `submodule`
- **Default:**

  ```nix
  {
    digest = "sha256:558394a23dd3c36f2d3a64b51865fd09908010e80a542cea5e75c2af543ed62a";
    pullPolicy = "IfNotPresent";
    repository = "docker.io/library/nats";
    tag = "2.15.3-alpine";
  }
  ```

### `image.digest`

Resolved manifest digest, `sha256:` followed by 64 hex characters. What will actually run. Null means not resolved.

- **Type:** `null or string`
- **Default:** the package's digest while `tag` is the package's tag, otherwise null

### `image.note`

Whatever a person wanted to say about this pin. Kix never reads it and a promotion never discards it. Declared here for the same reason as the three fields above: a pin carries its own record-keeping, and the option accepts the whole pin rather than a subset of it.

- **Type:** `null or string`
- **Default:** `null`

### `image.promotedBy`

Who resolved this pin, for the record. Null when unknown.

- **Type:** `null or string`
- **Default:** `null`

### `image.pullPolicy`

imagePullPolicy for containers using this image. Null leaves it to Kubernetes.

- **Type:** `null or string`
- **Default:** `"IfNotPresent"`

### `image.repository`

Image repository, registry host included.

- **Type:** `string`
- **Default:** `"docker.io/library/nats"`

### `image.resolvedAt`

When this pin was resolved, RFC 3339. Null when unknown.

- **Type:** `null or string`
- **Default:** `null`

### `image.sourceRev`

Revision of the source the image was built from, when Kix built it. Null for upstream images.

- **Type:** `null or string`
- **Default:** `null`

### `image.tag`

Image tag. What was asked for.

- **Type:** `string`
- **Default:** `"2.15.3-alpine"`

### `jetstream.enabled`

Enable JetStream persistence. When `true`, each pod mounts a PersistentVolumeClaim at `/data` for stream and consumer state. When `false`, the StatefulSet creates no volumes and serves core NATS (in-memory publish/subscribe) only.

- **Type:** `boolean`
- **Default:** `true`

### `metrics.enabled`

Run the `prometheus-nats-exporter` sidecar in each pod. When the cluster also has a `prometheus` provider, Kix creates a metrics Service, a ServiceMonitor, and Prometheus alert rules. Changing `metrics.enabled` restarts the pods; adding or removing a `prometheus` provider does not.

- **Type:** `boolean`
- **Default:** `true`

### `metrics.image`

Container image for the `prometheus-nats-exporter` sidecar.

- **Type:** `submodule`
- **Default:**

  ```nix
  {
    digest = "sha256:4b8ddc1c86fec360b5cd3d5e1fbc6fb52bdafd5805bba3901cc52926538af255";
    pullPolicy = "IfNotPresent";
    repository = "docker.io/natsio/prometheus-nats-exporter";
    tag = "0.20.3";
  }
  ```

### `metrics.image.digest`

Resolved manifest digest, `sha256:` followed by 64 hex characters. What will actually run. Null means not resolved.

- **Type:** `null or string`
- **Default:** the package's digest while `tag` is the package's tag, otherwise null

### `metrics.image.note`

Whatever a person wanted to say about this pin. Kix never reads it and a promotion never discards it. Declared here for the same reason as the three fields above: a pin carries its own record-keeping, and the option accepts the whole pin rather than a subset of it.

- **Type:** `null or string`
- **Default:** `null`

### `metrics.image.promotedBy`

Who resolved this pin, for the record. Null when unknown.

- **Type:** `null or string`
- **Default:** `null`

### `metrics.image.pullPolicy`

imagePullPolicy for containers using this image. Null leaves it to Kubernetes.

- **Type:** `null or string`
- **Default:** `"IfNotPresent"`

### `metrics.image.repository`

Image repository, registry host included.

- **Type:** `string`
- **Default:** `"docker.io/natsio/prometheus-nats-exporter"`

### `metrics.image.resolvedAt`

When this pin was resolved, RFC 3339. Null when unknown.

- **Type:** `null or string`
- **Default:** `null`

### `metrics.image.sourceRev`

Revision of the source the image was built from, when Kix built it. Null for upstream images.

- **Type:** `null or string`
- **Default:** `null`

### `metrics.image.tag`

Image tag. What was asked for.

- **Type:** `string`
- **Default:** `"0.20.3"`

### `metrics.interval`

Scrape interval (e.g. "30s"). Null = use Prometheus default.

- **Type:** `null or string`
- **Default:** `null`

### `metrics.resources`

Container resource requests and limits. Each field keeps its default until set, and null removes a default.

- **Type:** `submodule`
- **Default:**

  ```nix
  {
    limits = {
      cpu = "500m";
      memory = "128Mi";
    };
    requests = {
      cpu = "50m";
      memory = "64Mi";
    };
  }
  ```

### `metrics.resources.claims`

Dynamic resource claims the container uses. Null leaves it unset.

- **Type:** `null or (list of (submodule))`
- **Default:** `null`

### `metrics.resources.claims.*.name`

Name of an entry in the pod's `resourceClaims`.

- **Type:** `string`

### `metrics.resources.claims.*.request`

Request within the claim to use. Null uses the whole claim.

- **Type:** `null or string`
- **Default:** `null`

### `metrics.resources.limits`

Resource quantities by name.

- **Type:** `open submodule of attribute set of Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `{ }`

### `metrics.resources.limits.cpu`

The cpu quantity. Null leaves it unset.

- **Type:** `null or Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `"500m"`

### `metrics.resources.limits.ephemeral-storage`

The ephemeral-storage quantity. Null leaves it unset.

- **Type:** `null or Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `null`

### `metrics.resources.limits.memory`

The memory quantity. Null leaves it unset.

- **Type:** `null or Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `"128Mi"`

### `metrics.resources.requests`

Resource quantities by name.

- **Type:** `open submodule of attribute set of Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `{ }`

### `metrics.resources.requests.cpu`

The cpu quantity. Null leaves it unset.

- **Type:** `null or Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `"50m"`

### `metrics.resources.requests.ephemeral-storage`

The ephemeral-storage quantity. Null leaves it unset.

- **Type:** `null or Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `null`

### `metrics.resources.requests.memory`

The memory quantity. Null leaves it unset.

- **Type:** `null or Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `"64Mi"`

### `replicas`

Number of NATS server pods. Must be `1` when `clustered` is `false`, and an odd number of at least `3` when `clustered` is `true`.

- **Type:** `positive integer, meaning >0`
- **Default:** `3` when `clustered` is `true`, otherwise `1`

### `resources`

CPU and memory requests and limits for the `nats` container. The defaults (`500m` CPU and `1Gi` memory) are sized for development. For production JetStream clusters, upstream NATS recommends equal requests and limits of at least `2` CPU and `8Gi` memory. `limits.memory` also sets the default `GOMEMLIMIT` (80% of the limit).

- **Type:** `submodule`
- **Default:**

  ```nix
  {
    limits = {
      cpu = "500m";
      memory = "1Gi";
    };
    requests = {
      cpu = "500m";
      memory = "1Gi";
    };
  }
  ```

### `resources.claims`

Dynamic resource claims the container uses. Null leaves it unset.

- **Type:** `null or (list of (submodule))`
- **Default:** `null`

### `resources.claims.*.name`

Name of an entry in the pod's `resourceClaims`.

- **Type:** `string`

### `resources.claims.*.request`

Request within the claim to use. Null uses the whole claim.

- **Type:** `null or string`
- **Default:** `null`

### `resources.limits`

Resource quantities by name.

- **Type:** `open submodule of attribute set of Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `{ }`

### `resources.limits.cpu`

The cpu quantity. Null leaves it unset.

- **Type:** `null or Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `"500m"`

### `resources.limits.ephemeral-storage`

The ephemeral-storage quantity. Null leaves it unset.

- **Type:** `null or Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `null`

### `resources.limits.memory`

The memory quantity. Null leaves it unset.

- **Type:** `null or Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `"1Gi"`

### `resources.requests`

Resource quantities by name.

- **Type:** `open submodule of attribute set of Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `{ }`

### `resources.requests.cpu`

The cpu quantity. Null leaves it unset.

- **Type:** `null or Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `"500m"`

### `resources.requests.ephemeral-storage`

The ephemeral-storage quantity. Null leaves it unset.

- **Type:** `null or Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `null`

### `resources.requests.memory`

The memory quantity. Null leaves it unset.

- **Type:** `null or Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `"1Gi"`

### `settings`

Extra `nats.conf` settings merged over this package's defaults. Keys in `settings`, `settings.cluster`, and `settings.jetstream` must be lowercase. When NATS accepts aliases for a key (such as `max_file` for `max_file_store`), use `max_file_store` (the primary name). Kix rejects top-level settings that this package manages (ports, listen addresses, `client_advertise`, `http_base_path`, `server_name`, `pid_file`, lame duck timings, `store_dir`, log files, syslog, `ports_file_dir`, and client authentication) or does not support (remote syslog, the profiling port, client TLS, NATS accounts, JWT authentication, leaf nodes, gateways, WebSocket, and MQTT). `settings.cluster` is allowed only when `clustered` is `true`, and rejects `name`, `port`, `listen`, `host`, `net`, `routes`, `authorization`, and `tls`. `settings.jetstream` is allowed only when `jetstream.enabled` is `true`, and rejects `store_dir`, `enabled`, and encryption settings (`key`, `prev_key`, `cipher`, and `tpm`).

- **Type:** `attribute set of anything`
- **Default:** `{ }`
- **Example:**

  ```nix
  {
    jetstream = {
      max_memory_store = 1073741824;
    };
    max_payload = 8388608;
  }
  ```

### `storage.size`

Size of each pod's `/data` PersistentVolumeClaim when JetStream is enabled. Also sets the default `settings.jetstream.max_file_store`. Kubernetes cannot resize a StatefulSet's `volumeClaimTemplates` in place, so changing `storage.size` does not resize existing PersistentVolumeClaims.

- **Type:** `Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `"10Gi"`

### `storage.storageClassName`

StorageClass for each pod's JetStream volume. When `null`, Kix uses the cluster's `storageClasses` provider if configured, or falls back to the cluster's default StorageClass.

- **Type:** `null or string`
- **Default:** `null`