Skip to content

Installing RabbitMQ with MQTT plugin using Helm chart does not expose port 1883

Deploy RabbitMQ with MQTT plugin enabled using Helm to a Kubernetes cluster. This was for for a Home Assistant MQTT integration, with the Home Assistant instance running outside Kubernetes cluster.

Problem

Installing RabbitMQ with MQTT plugin does not expose port 1883

Install using the Bitnami Helm chart for RabbitMQ with the MQTT plugin enabled. https://artifacthub.io/packages/helm/bitnami/rabbitmq

helm install rabbit oci://registry-1.docker.io/bitnamicharts/rabbitmq --set extraPlugins=rabbitmq_mqtt

Confirm MQTT plugin is enabled.

 $ kubectl exec rabbit-rabbitmq-0 -- rabbitmq-plugins list -E

Listing plugins with pattern ".*" ...
 Configured: E = explicitly enabled; e = implicitly enabled
 | Status: * = running on rabbit@rabbit-rabbitmq-0.rabbit-rabbitmq-headless.default.svc.cluster.local
 |/
[E*] rabbitmq_management         3.13.1
[E*] rabbitmq_management_agent   3.13.1
[E*] rabbitmq_mqtt               3.13.1
[E*] rabbitmq_peer_discovery_k8s 3.13.1
[E*] rabbitmq_prometheus         3.13.1

But the port 1883 is not exposed.

$ kubectl get service rabbit-rabbitmq
NAME              TYPE           CLUSTER-IP    EXTERNAL-IP       PORT(S)                                                         AGE
rabbit-rabbitmq   LoadBalancer   10.108.0.95   192.168.200.205   5672:31493/TCP,4369:31715/TCP,25672:31831/TCP,15672:30294/TCP   74s

Error: UPGRADE FAILED: YAML parse error on rabbitmq/templates/statefulset.yaml: error converting YAML to JSON: yaml: line 149: could not find expected ':'

Naively trying to set the deployment to expose the 1883 port fails.

$ helm upgrade rabbit oci://registry-1.docker.io/bitnamicharts/rabbitmq --set extraPlugins=rabbitmq_mqtt,service.type=LoadBalancer,extraContainerPorts=["1883"]
Pulled: registry-1.docker.io/bitnamicharts/rabbitmq:14.0.1
Digest: sha256:37d3efe9bdb7debabf47a6d23457522edd2549a8777b8cad5087103eb1a3a2e9
Error: UPGRADE FAILED: YAML parse error on rabbitmq/templates/statefulset.yaml: error converting YAML to JSON: yaml: line 149: could not find expected ':' 

Solution

Create values.yaml file with the following content.

extraPlugins: rabbitmq_mqtt
ingress:
  enabled: false
service:
  type: LoadBalancer
  extraPorts:
   - name: mqtt
     port: 1883
     targetPort: 1883
extraContainerPorts:
 - name: mqtt
   containerPort: 1883

This adds port 1883 to the service and container.

Then install RabbitMQ using the values.yaml file.

helm install rabbit oci://registry-1.docker.io/bitnamicharts/rabbitmq -f values.yaml

Port 1883 is now exposed.

$ kubectl get service rabbit-rabbitmq
NAME              TYPE           CLUSTER-IP    EXTERNAL-IP       PORT(S)                                                                        AGE
rabbit-rabbitmq   LoadBalancer   10.97.227.3   192.168.200.205   5672:31808/TCP,4369:32440/TCP,25672:30089/TCP,15672:30171/TCP,1883:30629/TCP   

Test Connection to MQTT

Find username and password for RabbitMQ

Default user is user and password is stored in a secret.

$ kubectl get secret --namespace default rabbit-rabbitmq -o jsonpath="{.data.rabbitmq-password}" | base64 -d
XXXXXXXXXXXXXXXX

Using mqttcli pub and sub commands to test connection.

Subscribing to a topic.

 $ sub -username user -password XXXXXX -broker 192.168.200.205:1883 -topic foo -auto-reconnect &
[1] 85860
2024/04/16 10:33:30 connected: 192.168.200.205:1883
2024/04/16 10:33:30 subscribed: foo

Publish message to the topic.

$ echo "Message $(date)" | pub -username user -password XXXXXX -broker 192.168.200.205:1883 -topic foo -auto-reconnect
2024/04/16 10:34:47 connected: 192.168.200.205:1883
2024/04/16 10:34:47 published: [foo] [77 101 115 115 97 103 101 32 84 117 101 32 49 54 32 65 112 114 32 49 48 58 51 52 58 52 55 32 66 83 84 32 50 48 50 52 10]
2024/04/16 10:34:47 [foo] Message Tue 16 Apr 10:34:47 BST 2024

It might be clearer to run the commands in separate terminals.