Table of Contents |
---|
Prequisite:
A running HiveMQ Cluster Install HiveMQ on the AKS cluster
Successful connection to cluster using kubectl (kubectl get pods)Access to infrastructure with Kubectl. E.g.
Running HiveMQ Cluster Install HiveMQ using Kubernetes Operator
Values.yaml file https://hivemq.atlassian.net/wiki/spaces/KB/pages/2691039283/Install+HiveMQ+using+Kubernetes+Operator#Add-Helm-repository-and-download-values.yaml-file
(optional) You have added a valid license to the HiveMQ broker Add a valid license to HiveMQ Cluster
(optional) You have added a load balancer and verified the connection Expose MQTT port 1883 and test message flow using MQTT CLI
Kubectl, Helm and MQTT CLI Prerequisite - Software Packages
Install Kafka using helm
Create a namespace for Kafka and switch the context to it:
Code Block language bash kubectl create namespace kafka;
Code Block kubectl config set-context --current --namespace=kafka
Add the repository for the Kafka Helm chart to your package manager.
Code Block language bash helm repo add bitnami https://charts.bitnami.com/bitnami
Code Block language bash helm repo update bitnami
Deploy the Kafka server using the Helm chart.
Additional step with AWS EKS cluster:
You will need to configure the Amazon EBS CSI driver. You can find detailed steps How to configure Amazon EBS CSI driver for working PersistentVolumes in EKSThe below command deploys Kafka with 2 brokers (replicas).
Code Block language bash helm upgrade --install kafka bitnami/kafka --namespace=kafka --set replicaCount=2
Please notice the output of the command above, it provides critical data that is used for the next steps
Consumers can access Kafka via port 9092 on the following DNS name from within your cluster:
kafka.kafka.svc.cluster.local
The CLIENT listener for Kafka client connections from within your cluster has been configured with the following security settings: SASL authentication
To connect a client to your Kafka:
username="user1"
To get the password execute the command below:(skip % at the end)
Code Block language bash kubectl get secret kafka-user-passwords --namespace kafka \ -o jsonpath='{.data.client-passwords}' | base64 -d | cut -d , -f 1;
Configuring the Kafka Extension
Setting up the Kafka license as a ConfigMap
If you skip this step, then the kafka-extension will start in trial mode, limited to 5h, and will be automatically disabled by the HiveMQ broker after 5h.
...
HiveMQ Enterprise Extension For Kafka requires a separate license file, e.g. kafka-license.elic, in the $HIVEMQ_HOME/license directory. To add the kafka-license.elic along with the hivemq-license.lic, create a new configmap hivemq-license including all desired license files:
Code Block language bash kubectl create configmap hivemq-license --namespace=hivemq \ --from-file hivemq-license.lic \ --from-file kafka-license.elic
Edit the values.yaml file of the hivemq-operator, section
hivemq.configMaps
. Update this:Code Block configMaps: [] # ConfigMaps to mount to the HiveMQ pods. These can be mounted to existing directories without shadowing the folder contents as well. #- name: hivemq-license # path: /opt/hivemq/license
To this:
Code Block configMaps: - name: hivemq-license path: /opt/hivemq/license
This will mount the content of the configMap
hivemq-license
to the directory/opt/hivemq/license
of the hivemq-broker pods.
Configuring the extension
HiveMQ Enterprise Extension For Kafka is preinstalled with HiveMQ so once you enable it, it will look for its configuration file. You must prepare this file before enabling the extension. If you skip this step, the extension will not find its configuration file and will not load any configuration.
Prepare a simple configuration file for kafka-extension as in the example below.
this example configuration will map all incoming MQTT publish packets to the topic “test” in Kafka; and will map the topic “test” in Kafka to the topic “test” in the HiveMQ broker
Use your password in
<password>here_is_your_password</password>
, that you successfully retrieved with this command a few steps ago:Code Block language bash kubectl get secret kafka-user-passwords --namespace kafka \ -o jsonpath='{.data.client-passwords}' | base64 -d | cut -d , -f 1;
Here is the file:
...
Edit values.yaml file of
hivemq-operator
and update section hivemq.extensions, havingname: hivemq-kafka-extension
Update this:Code Block language yaml extensions: - name: hivemq-kafka-extension extensionUri: preinstalled enabled: false
To this:
Code Block language yaml extensions: - name: hivemq-kafka-extension extensionUri: preinstalled enabled: true configMap: kafka-config initialization: | # Fixes the location of the config.xml file [[ ! -f conf/config.xml ]] && [[ -f /conf-override/extensions/hivemq-kafka-extension/config.xml ]] && ln -s /conf-override/extensions/hivemq-kafka-extension/config.xml conf/config.xml
Re-deploy hivemq-operator with updated values.yaml
Code Block language bash helm upgrade hivemq --install hivemq/hivemq-operator --values values.yaml --namespace hivemq
– for ease of use we switch namespace back to hivemq
kubectl config set-context --current --namespace=hivemq
Check if the license and configuration is applied correctly
If everything is correct,
...
Kafka dashboard is visible in the HiveMQ Control Center:
...
Testing Message Flow between HiveMQ Broker and Kafka using MQTT CLI
Subscribe a reference MQTT client to the topic “test”, The output shows the topic name and message: (please update your hostname with the DNS name or public IP address of your hivemq-hivemq-mqtt service, 20.113.46.120 in our test)
Code Block language bash mqtt subscribe --topic '#' --host 20.113.46.120 --port 1883 -q 1 --showTopics
Do not close this terminal session!
From a different terminal session, publish a message to the topic “test”:(please update your hostname with the DNS name or public IP address of your hivemq-hivemq-mqtt service, 20.113.46.120 in our test)
Code Block language bash mqtt publish --topic test --message Hello --host 20.113.46.120 --port 1883 -q 1
If everything is correct, the subscriber will indefinitely receive the message we published. You can stop this by terminating the execution of the command by pressing Ctrl+C.
Code Block mqtt subscribe --topic '#' --host $hivemqhost --port 1883 -q 1 --showTopics test: Hello test: Hello test: Hello test: Hello ........
the Kafka Dashboard in the HiveMQ Control Center shows incoming and outgoing Kafka messaging:
...