Table of Contents |
---|
Prequisite
:Access to a running HiveMQ Cluster using Kubectlvaluesinfrastructure with Kubectl, E.g.
Running HiveMQ Cluster Install HiveMQ using Kubernetes Operator
Values.yaml file https://hivemq.atlassian.net/wiki/spaces/HMSKB/pages/2691039283/Install+HiveMQ+onusing+theKubernetes+AKS+cluster#AddOperator#Add-Helm-repository-and-download-values.yaml-file
Kubectl, Helm and MQTT CLI Prerequisite - Software Packages
Using Loadbalancer
Exposing port 1883 using Load Balancer
Exposing ip via load balancer in the following steps makes it public. HiveMQ recommends securing the authentication and authorisation of clients for production environment. E.g. Setting up ESE Extension using HiveMQ Operator
Please check out HiveMQ authentication and authorisation extensions to control client access and scope. https://www.hivemq.com/products/extensions/
Open values.yaml and search for port 1883 under hivemq.ports.port
Code Block ports: - name: "mqtt" port: 1883 expose: true patch: - '[{"op":"add","path":"/spec/selector/hivemq.com~1node-offline","value":"false"},{"op":"add","path":"/metadata/annotations","value":{"service.spec.externalTrafficPolicy":"Local"}}]' # If you want Kubernetes to expose the MQTT port to external traffic # - '[{"op":"add","path":"/spec/type","value":"LoadBalancer"}]'
Uncomment and expose the loadbalancer
Code Block ports: - name: "mqtt" port: 1883 expose: true patch: - '[{"op":"add","path":"/spec/selector/hivemq.com~1node-offline","value":"false"},{"op":"add","path":"/metadata/annotations","value":{"service.spec.externalTrafficPolicy":"Local"}}]' # If you want Kubernetes to expose the MQTT port to external traffic - '[{"op":"add","path":"/spec/type","value":"LoadBalancer"}]'
Save the file and apply the changes
Code Block helm upgrade hivemq --install hivemq/hivemq-operator --values values.yaml
Check if the service for port 1883 has an external IP address now (98.67.128.195 in our case its hivemq-hivemq-mqtt) and notice the external port IP.
Code Block kubectl get services
In case the external IP is not visible, you can uninstall hivemq and reinstall it again.
Uninstall HiveMQ
helm uninstall hivemq
Reapply the changes
helm upgrade hivemq --install hivemq/hivemq-operator --values values.yaml
Connect To Your HiveMQ Cluster using MQTT CLI
...
MQTT
...
CLI
...
Code Block |
---|
kubectl get hivemq-clusters |
Output similar to the following displays: (20.79.151.169 in our case)
Code Block |
---|
$ kubectl get hivemq-clusters
NAME SIZE IMAGE VERSION STATUS ENDPOINT MESSAGE
hivemq 3 hivemq/hivemq4 k8s-4.24.0 Running 20.79.151.169 Live updates completed successfully |
Create a subscriber
Code Block |
---|
mqtt sub -i SUB -h 2098.7967.151128.169195 -p 1883 -T -t '#' |
Create a publisher and publish the message. This should send a message to the subscriber.
Test: Hello
Code Block |
---|
mqtt publish --topic Test --message Hello --host 2098.7967.151128.169195 --port 1883 |
You have now successfully connected a new MQTT client to a HiveMQ cluster hosted on Azure.
...
To learn more ways to interact with HiveMQ, see the MQTT-CLI documentation.