Exposing MQTT Broker

Cluster information:

Kubernetes version: Bare metal
Installation method: snap
Host OS: Ubuntu Server 18

Question

I’m trying to run an MQTT broker inside of microk8s on my home network and am struggling a little. With my websites etc I would just use an ingress resource to expose 80 or 443, but I’m not sure what to do regarding something that isn’t a website. If I use ClusterIP for the service then I don’t have anything exposed externally, if I use NodePort I have to use a port in the 30000 range and would like to stick with 1883 that is the default for MQTT.

I have tried using NodePort with port 31883 but that didn’t work, or at least I couldn’t get it to work.

I was trying to not have to setup Metallb, but if thats the best way then so be it.

Thoughts?

If you are using baremetal LB or something similar, setup a service to expose the standard ports. That’s how my setup is done.

I have a mosquitto deployment and a service configured to route traffic in.

You can do something like that TCP will auto genrate port for you use that port with your node external Ip
node-external-Ip : nodePort-port

apiVersion: v1
kind: Service
metadata:
  name: mosquitto
  namespace: default
spec:
  selector:
    app: mosquitto
  ports:
    - name: mqtt
      port: 1883
      targetPort: 1883
      protocol: TCP
  type: NodePort