This document outlines the testing procedure for testing that the HA NATS has been installed successfully.
Pre-requisites
-
Please point your
kubectlto 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
-
Open the Kubernetes Cluster Management Tool (GKE, EKE, Rancher, …)
-
In the cluster, two workloads should be visible in the namespace that you deployed the HA NATS on
natsandnats-box. -
Open the
natsworkload. The following information should be visible:-
Under the
Managed Podssection, three pods are available (nats-0, nats-1, nats-2) -
Under
Exposing servicestwo services are available (nats, nats-svc). Both should be ClusterIP, and only thenats-svcshould have value in theEndpointscolumn. Note down the value. We will later on refer to this value as NATS_SVC_ENDPOINT.
-
Steps for Access Testing
-
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 -
Check that the pub/sub is working.
nats sub --user=$u --password=$p test & nats pub --user=$u --password=$p test hiThe output similar to the following will be observed:
Received on "test" hiThe "HA NATS" is working at this point from within the namespace.
-
For testing from outside the namespace, we will consider the following scenarios:
-
From within the cluster
-
Deploy a
nats-boxin some other namespace besides$n. In this example, we will deploy thenats-boxon thenats-testnamespace. Note that this namespace should not exist in the cluster. If used, use something else.nsp=nats-test kubectl create namespace $nsp kubectl apply -n $nsp -f https://nats-io.github.io/k8s/tools/nats-box.ymlYou can check that the pod has been deployed by examining the output of the command:
kubectl get pods -n $nsp -
Get into the
nats-boxpod.kubectl exec -n $nsp -it pods/nats-box -- /bin/sh -l -
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 hiExpect to get errors like
dial tcp: no such host -
The pub/sub should work once we specify the correct host.
host="http://NATS_SVC_ENDPOINT" nats -s $host sub --user=$u --password=$p test & nats -s $host pub --user=$u --password=$p test holaWe can take advantage of the Kube DNS to simplify the hostname.
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
-
-
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