Deploying Mosquitto MQTT broker on Minikube, error while configuring an Ingress

My goal in to install a simple Mosquitto broker on Minikube (without certificate). Mu problem is that I cannot add an Ingress.

I am a real beginer in Kubernetes I hope this question is not stupid, I have searched for a solution without success. So I have a VM (Vmware) with Ubuntu 20.04 on it. Minikube 1.26 is running perfectly well on it (with Docker that is intalled on the VM) :

minkube start

I have deployed Mosquitto on Minikube using the following yaml files :

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mosquitto
  namespace: default
spec:
replicas: 1
  selector:
matchLabels:
  name: mosquitto
  template:
    metadata:
      labels:
        name: mosquitto
    spec:
      containers:
        - name: mosquitto
          image: eclipse-mosquitto:2.0.12
          ports:
          - containerPort: 1883
      volumeMounts:
          - name: mosquitto-config
            mountPath: /mosquitto/config/mosquitto.conf
            subPath: mosquitto.conf
          - mountpath: etc/mosquitto
            name: data
      volumes:
      - name: mosquitto-config
        configMap:
          name: mosquitto-configmap
      - name: data
      pesristentVolumeclaim:
          claimName: moquitto-data

Persistent volume :

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mosquitto-data
  namespace: default
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi

Config Map:

apiVersion: v1
kind: ConfigMap
metadata:
  name: mosquitto-configmap
  namespace: default
data:
  mosquitto.conf: |
    listener 1883
    allow_anonymous true
    protocol mqtt
    persistence true
    persistence_location /mosquitto/data
    log_dest stdout

Service (NodePort type):

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

I have then installed a ingress-ngninx controller to be able to do TCP o (ingress by itself only allows http and https).

minikube addons enable ingress

All seems to run good : runing controler

Now when I add my Ingress with the following yaml,

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    k8s.io/ingress-nginx : nginx
  name: mosquitto-ingress
spec:
  rules:
  - host: talenddemo.net
    tcp:
      paths:
      - path: /mqtt
        backend:
          serviceName: mosquitto-service
          servicePort: 1883

the computer says "no". The error message is "The server could not find the requested resource" enter image description here

Question 1 : What did I do wrong ?

Question 2 : With which address should I request connection to the MQTT broker from a MQTT client ?

Note : the namespace for the ingress controller is different from moquitto namesapce, would that be the cause ?

Many Thanks !!

Upvotes: 0

Views: 962

Answers (1)

hardillb
hardillb

Reputation: 59816

You can not use normal ingress to expose native MQTT.

Ingress is used to expose HTTP based protocols, native MQTT is not HTTP based.

Nginx will not help in this case because you are still trying to set up http virtual host and http path proxying which still won't work.

You have 2 choices

  1. Modify your mosquitto.conf to set the protocol to websockets. MQTT over Websockets is bootstrapped over HTTP so will work. This does mean you're clients will also need to use MQTT over Websockets.

  2. Enable metallb and expose the service a load balancer on a dedicated IP address. This is a lot more work and will require a bunch of network planning.

You might be able to get nginx to work as a load balancer instead of metallb, but you will still need to expose as a load balanced service. https://kubernetes.github.io/ingress-nginx/user-guide/exposing-tcp-udp-services/

Upvotes: 3

Related Questions