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.

Pre-requisites

  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.

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

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

    The output similar to the following will be observed:

    CODE
    Received on "test"
    hi

    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.

        CODE
        nsp=nats-test
        kubectl create namespace $nsp
        kubectl apply -n $nsp -f https://nats-io.github.io/k8s/tools/nats-box.yml

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

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

        CODE
        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.

        CODE
        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.

        CODE
        host="http://NATS_SVC_ENDPOINT"
        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.

        CODE
        host="nats-svc.$n.svc.cluster.local"
        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.

CODE
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.