Troubleshooting NATS

10. Troubleshooting NATS#

In case you need to troubleshoot NATS, such as debug, look at streams, subjects, and users, you can use the NATS-box sidecar container in the NATS pod.

This section addresses operators who face NATS that isn’t working as they expect it. It assumes that you deployed Nubus for Kubernetes through helm as nubus release in the namespace $NUBUS_NAMESPACE.

10.1. Prerequisites#

Before you can start, you need to retrieve the NATS credentials. To retrieve the credentials from the Kubernetes secret and store them in environment variables for further use, use the command in Listing 10.1.

Listing 10.1 Retrieve NATS credentials#
$ NATS_USER=admin
$ NATS_PASSWORD=$(kubectl get secrets \
      -n $NUBUS_NAMESPACE \
      nubus-provisioning-nats-admin \
      -o"jsonpath={.data.password}" | base64 -d)

10.2. NATS debug session#

With the credentials from Prerequisites, you can start a debug session as shown in Listing 10.2.

Listing 10.2 Start debug session for NATS#
$ kubectl debug \
   -n $NUBUS_NAMESPACE \
   -it nubus-provisioning-nats-0 \
   --env NATS_USER="${NATS_USER}" \
   --env NATS_PASSWORD="${NATS_PASSWORD}" \
   --image=docker.io/natsio/nats-box:0.18.1-nonroot \
   -- /bin/sh

Then, in the NATS-box shell, you can use the nats CLI tool. Use a configuration context as shown in Listing 10.3.

Listing 10.3 Use configuration context#
$ nats context \
   add nubus \
   --server nats://127.0.0.1:4222 \
   --user "${NATS_USER}" \
   --password "${NATS_PASSWORD}"

To inspect streams or the key-value store, use the commands shown in Listing 10.4.

Listing 10.4 Inspect streams or key-value store#
$ nats stream ls
$ nats kv ls

NATS also provides commands to manage and interact with streams and the key-value stores:

  • nats stream view

  • nats stream info

  • nats consumer info

  • nats kv ls SUBSCRIPTIONS

  • nats kv get CREDENTIALS <key>

See also

nats | NATS Docs

for more information about nats.