NATS
Setup
Prepared values and manifests are in repo home.mixi.cz:/srv/git/repos/home/automation.git in folder kube/nats/.
- Install helm repo and get default NATS Helm values if needed.
helm repo add nats https://nats-io.github.io/k8s/helm/charts/ helm inspect values nats/nats > values.yaml - to enable authentication using memory resolver, create NKEYs accounts and users (here is also included user leaf-mqtt for leaf node):
# set environment . env.sh # create operator OP and account ACC (use second key for signing when asked) nsc add operator -n OP --sys --generate-signing-key nsc add account -n APP -i nsc edit account APP --js-disk-storage -1 --js-mem-storage -1 nsc edit account --sk generate # create user accounts (use second key for signing when asked) nsc add user --name mixi -a APP -i nsc add user --name app -a APP -i nsc add user --name nats-box -a APP -i nsc add user --name leaf-mqtt -a APP -i nsc generate config --mem-resolver --config-file ./resolver.conf && mv ./resolver.conf nats-accounts/ cp nsc/keys/creds/OP/APP/nats-box.creds nsc/keys/creds/OP/APP/app.creds nats-user-creds/ kubectl create configmap nats-accounts --from-file=nats-accounts/resolver.conf kubectl create secret generic nats-leaf-mqtt-creds --from-file=nsc/keys/creds/OP/APP/leaf-mqtt.creds kubectl create secret generic nats-user-creds --from-file=./nats-user-creds - in case there is later change in account database, config map can be updated this way:
# update of config map: kubectl get configmaps nats-accounts -o yaml > tmp-cm-nats-accounts.yaml # ... edit tmp-cm-nats-accounts.yaml (paste nats-accounts/resolver.conf) ... kubectl apply -f tmp-cm-nats-accounts.yaml - run helm charts and kubernetes manifests
# install/update main cluster helm upgrade nats-home nats/nats --values helm-values-home-cluster.yaml --install kubectl apply -f nats-home-service.yaml # install/update MQTT leaf node helm upgrade nats-home-mqtt nats/nats --values helm-values-home-leaf-mqtt.yaml --install kubectl apply -f nats-mqtt-leaf-service.yaml
Subject catalog
All subjets are available both as native NATS subjects or MQTT topics. For translation rules see NATS documentation. In catalog, all subjects use NATS notation.
IoT
Generally uses JSON and plain text formats, with possible binary payload encoded as base64 strings (Google Protocol Buffers).
subjects
node.>-- Hardwario Tower communicationgateway.>-- Hardwario Tower gateway
streams
iot_node-- unlimited retention, captured subjects:node.>
home
PV = PhotoVoltaics, FVE = FotoVoltaická Elektrárna.
subjects
home.pv.inverter.data-- raw data from Goodwe inverter in JSON formathome.pv.inverter.sensors-- sensor information from Goodwe inverter in JSON formathome.pv.data.>-- structured and categorized data regarding PhotoVoltaics
streams
home_pv_inverter-- short retentionhome_pv_data-- TBD (more streams with various retention?)