Testing HA NATS Installation
This document outlines the testing procedure for testing that the HA NATS has been installed successfully.
Pre-requisites
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
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
nats
andnats-box
.Open the
nats
workload. The following information should be visible:Under the
Managed Pods
section, three pods are available (nats-0, nats-1, nats-2
)Under
Exposing services
two services are available (nats, nats-svc
). Both should be ClusterIP, and only thenats-svc
should have value in theEndpoints
column. 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.CODEkubectl exec -n $n -it deployment/nats-box -- /bin/sh -l
Check that the pub/sub is working.
CODEnats sub --user=$u --password=$p test & nats pub --user=$u --password=$p test hi
The output similar to the following will be observed:
CODEReceived on "test" hi
The "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-box
in some other namespace besides$n
. In this example, we will deploy thenats-box
on thenats-test
namespace. Note that this namespace should not exist in the cluster. If used, use something else.CODEnsp=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:
CODEkubectl get pods -n $nsp
Get into the
nats-box
pod.CODEkubectl 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.
CODEnats sub --user=$u --password=$p test & nats pub --user=$u --password=$p test hi
Expect to get errors like
dial tcp: no such host
The pub/sub should work once we specify the correct host.
CODEhost="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.
CODEhost="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