Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Prequisite: A running HiveMQ Cluster Install HiveMQ on the AKS cluster

Enable load balancer

  1. 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"}]'
  2. 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"}]'
  3. Save the file and apply the changes

    Code Block
    helm upgrade hivemq --install hivemq/hivemq-operator --values values.yaml
  4. Check if the service for port 1883 has an external IP address now (in our case its hivemq-hivemq-mqtt)

    Code Block
    kubectl get services

In case the external IP is not visible, you can uninstall hivemq and reinstall it again.

  1. Uninstall HiveMQ
    helm uninstall hivemq

  2. Reapply the changes
    helm upgrade hivemq --install hivemq/hivemq-operator --values values.yaml

Connect To Your HiveMQ Cluster

  • Once your HiveMQ cluster is up and running, you are ready to connect clients to the cluster with the MQTT-CLI. To obtain the exposed ENDPOINT of the created load balancer on which clients connect to your cluster, enter:

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
  • To start up the MQTT-CLI in shell mode, enter:Create a subscriber

Code Block
mqtt sh

...

sub -i SUB -h 20.79.151.169

...

Code Block
con -h -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 20.79.151.169 --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.Next steps: Testing the connection with MQTT CLI