nats deployment guide for CX on cloud
Add the helm respository
helm repo add expertflow-general https://expertflow.github.io/general
update the repo
helm repo update expertflow-general
create directory to save the helm chart values file
mkdir helm-values
clone the values file to update the values
helm show values expertflow-general/nats > helm-values/nats-custom-values.yaml
Update the nats’s values file for
Default password for the client is set to
Expertflow123
- YAML
auth: enabled: true token: "" credentials: - user: expertflow password: "Expertflow123"
deploy the nats helm chart
helm upgrade --install --namespace ef-external --values helm-values/nats-custom-values.yaml nats expertflow-general/nats
Manual Verification
Export the nats credentials
export NATS_USER=$(kubectl get secret --namespace ef-external nats -o jsonpath='{.data.*}' | base64 -d | sed -n 's/.*user: "\\([^"]*\\)".*/\\1/p' | head -n 1)
export NATS_PASS=$(kubectl get secret --namespace ef-external nats -o jsonpath='{.data.*}' | base64 -d | sed -n 's/.*password: "\\([^"]*\\)".*/\\1/p' | head -n 1)
You can create a pod to be used as a NATS client:
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: nats-client
namespace: ef-external
spec:
containers:
- name: cli
image: docker.io/bitnami/natscli
command: ["sleep", "infinity"]
env:
- name: NATS_USER
value: "$NATS_USER"
- name: NATS_PASS
value: "$NATS_PASS"
volumeMounts:
- mountPath: /etc/certs/ca
name: ca-cert
readOnly: true
- mountPath: /etc/certs/client
name: client-cert
readOnly: true
volumes:
- name: ca-cert
secret:
secretName: nats-ca-crt
- name: client-cert
secret:
secretName: nats-client-crt
EOF
login to the nats-client pod as a subscriber
kubectl exec --tty -i nats-client --namespace ef-external -- bash
and run these steps to launch a subscriber
nats -s nats://$NATS_USER:$NATS_PASS@nats.ef-external.svc.cluster.local:4222 \
--tlscert /etc/certs/client/tls.crt \
--tlskey /etc/certs/client/tls.key \
--tlsca /etc/certs/ca/tls.crt subscribe SomeSubject
Open an other terminal and connect to the nats-client pod as publisher
kubectl exec --tty -i nats-client --namespace ef-external -- bash
send messages to the subscriber
nats -s nats://$NATS_USER:$NATS_PASS@nats.ef-external.svc.cluster.local:4222 \
--tlscert /etc/certs/client/tls.crt \
--tlskey /etc/certs/client/tls.key \
--tlsca /etc/certs/ca/tls.crt publish SomeSubject "Some message"
if everything is working correct, published message/s should appear on the subscriber console. Sample screen session given below

Sample pub-sub session