Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Version History

« Previous Version 18 Next »

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/

  1. Open values.yaml and search for port 1883 under hivemq.ports.port

    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

    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

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

    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 using MQTT CLI

  • Create a subscriber

mqtt sub -i SUB -h 98.67.128.195 -p 1883 -T -t '#'
  • Create a publisher and publish the message. This should send a message to the subscriber. Test: Hello

mqtt publish --topic Test --message Hello --host 98.67.128.195 --port 1883

You have now successfully connected a new MQTT client to a HiveMQ cluster hosted on Azure.

Using Port Forwarding

Exposing port 1883 using Port Forwarding

  • Run the following command to get the services and look for the MQTT service (hivemq-hivemq-mqtt in our case)

    kubectl get services
  • Run the port forwarding as follows

    kubectl port-forward hivemq-hivemq-mqtt 1883:1883
  • After running this command, you can access your service on localhost:1883

Connect To Your HiveMQ Cluster using the MQTT CLI

  • Create a subscriber

mqtt sub -i SUB -h localhost -p 1883 -T -t '#'
  • Create a publisher and publish the message. This should send a message to the subscriber. Test: Hello

mqtt publish --topic Test --message Hello --host localhost --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.

  • No labels