Skip to main content
Skip table of contents

nats deployment guide for CX on cloud

Add the helm respository

CODE
helm repo add expertflow-general https://expertflow.github.io/general

update the repo

CODE
helm repo update expertflow-general

create directory to save the helm chart values file

CODE
mkdir helm-values

clone the values file to update the values

CODE
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

CODE
helm upgrade --install --namespace ef-external --values helm-values/nats-custom-values.yaml nats expertflow-general/nats

Manual Verification

Export the nats credentials

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

CODE
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

CODE
kubectl exec --tty -i nats-client --namespace ef-external -- bash

and run these steps to launch a subscriber

CODE
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

CODE
kubectl exec --tty -i nats-client --namespace ef-external -- bash

send messages to the subscriber

CODE
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

Screenshot 2025-02-08 235151.png

Sample pub-sub session

JavaScript errors detected

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

If this problem persists, please contact our support.