Skip to main content
Skip table of contents

Testing HA NATS Installation

This document outlines the testing procedure for testing that the HA NATS has been installed successfully.


  1. Please point your kubectl to point to the correct cluster before moving forward.

Setup and Access Testing

The cluster-wide NATS can be tested with the kubectl tool and the GCP console through the browser.

Since the cluster has protected accounts, for testing purpose, please create an account for testing and use the user and password in the command while using the cli tool: --user=$u --password=$p, where $u represent the user and $p is the password for the user. We will use $n to denote the namespace.

Steps for Setup Testing

  1. Open the Kubernetes Cluster Management Tool (GKE, EKE, Rancher, …)

  2. In the cluster, two workloads should be visible in the namespace that you deployed the HA NATS on nats and nats-box.

  3. Open the nats workload. The following information should be visible:

    1. Under the Managed Pods section, three pods are available (nats-0, nats-1, nats-2)

    2. Under Exposing services two services are available (nats, nats-svc). Both should be ClusterIP, and only the nats-svc should have value in the Endpoints column. Note down the value. We will later on refer to this value as NATS_SVC_ENDPOINT.

Steps for Access Testing

  1. In a terminal, enter the following command to get into the nats-box. It provides basic tools to test the NATS installation.

    kubectl exec -n $n -it deployment/nats-box -- /bin/sh -l
  2. Check that the pub/sub is working.

    nats sub --user=$u --password=$p test &
    nats pub --user=$u --password=$p test hi

    The output similar to the following will be observed:

    Received on "test"

    The "HA NATS" is working at this point from within the namespace.

  3. For testing from outside the namespace, we will consider the following scenarios:

    1. From within the cluster

      1. Deploy a nats-box in some other namespace besides $n. In this example, we will deploy the nats-box on the nats-test namespace. Note that this namespace should not exist in the cluster. If used, use something else.

        kubectl create namespace $nsp
        kubectl apply -n $nsp -f

        You can check that the pod has been deployed by examining the output of the command:

        kubectl get pods -n $nsp
      2. Get into the nats-box pod.

        kubectl exec -n $nsp -it pods/nats-box -- /bin/sh -l
      3. Just publishing the data like before should not work, as NATS is not available in the namespace.

        nats sub --user=$u --password=$p test &
        nats pub --user=$u --password=$p test hi

        Expect to get errors like dial tcp: no such host

      4. The pub/sub should work once we specify the correct host.

        nats -s $host sub --user=$u --password=$p test &
        nats -s $host pub --user=$u --password=$p test hola

        We can take advantage of the Kube DNS to simplify the hostname.

        nats -s $host sub --user=$u --password=$p test &
        nats -s $host pub --user=$u --password=$p test hola
    2. From outside the cluster: Just run the above steps in order from the local machine (outside the cluster). It should not be possible to do the pub/sub.

Cleaning up Resources Used for Testing

It's a good practice to clean up the resources used after the completion of the test.

kubectl delete -n $nsp pods/nats-box
kubectl delete namespace $nsp

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.