5

I have been trying to set up ChirpStack in a Kubernetes space, but it doesn't seem to be working for me, and I can't find any resources online that have been the solution.

**chirpstack-application-server-6d6f8d699c-nlrmx   1/1     Running            0          44s\
chirpstack-gateway-bridge-5454b7f9f-fm5wl          1/1     Running            0          73s\
chirpstack-mosquitto-646899d74d-d7bhl              0/1     CrashLoopBackOff   3          85s\
chirpstack-network-server-66cdf9bdf7-rhzg5         1/1     Running            0          55s**

Above is every pod I have atm. App-server, net-server, gateway-bridge all spin up and run, however the Mosquitto broker moves to 'Complete' and goes right into the CrashLoopBackOff.

I have figured it might be something to do with a lack of config, so I've spent a few days putting together the mosquitto.conf file with "allow_anonymous true" hoping to get a connection from any of my ChirpStack components, but the logs just indicate an mqtt connection refused error.

Output of kubectl logs chirpstack-application-server

time="2020-12-10T15:01:41Z" level=error msg="integration/mqtt: connecting to broker error, will retry in 2s: Network Error : dial tcp 10.244.146.236:1883: i/o timeout"

Because no connection could be made, I assumed it was the opposite and I needed to add in the password_file and make allow_anonymous false. Below is my current config if anyone might have an idea what is wrong.

configMap-1.yml

kind: ConfigMap
metadata:
  name: mosquitto-password
  namespace: ****
  labels:
    app: chirpstack-mosquitto  
data:
  password_file.txt: |
    admin:admin
    user:user
    app-server:app-server
    net-server:net-server
    gateway-bridge:gateway-bridge

configMap.yml

kind: ConfigMap
metadata:
  name: mosquitto-config
  namespace: ****
  labels:
    app: chirpstack-mosquitto  
data:
  mosquitto.conf: |    
    persistence true
    persistence_location /mosquitto/data/
    # per_listener_settings false
    log_dest stdout
    # listener 1886
    listener 1883
    protocol mqtt
    # Defaults to false, unless there are no listeners defined in the configuration
    # file, in which case it is set to true, but connections are only allowed from
    # the local machine.
    allow_anonymous false
    password_file /.config/mosquitto/auth/password_file.txt
    #    cafile: /mosquitto/config/certs/ca.crt
    #    certfile: /mosquitto/config/certs/server.crt
    #    keyfile: /mosquitto/config/certs/server.key
    require_certificate false
    use_identity_as_username false

deployment.yml

kind: Deployment
metadata:
  name: chirpstack-mosquitto
  namespace: ****  
spec:
  replicas: 1
  selector:
    matchLabels:
      app: chirpstack-mosquitto
  template:
    metadata:
      labels:
        app: chirpstack-mosquitto
    spec:
      containers:
      - name: chirpstack-mosquitto
        image: ****/chirpstack/eclipse-mosquitto:1.6.12
        ports:
        - containerPort: 1883
        volumeMounts:
        - name: password-file
          mountPath: /.config/mosquitto/auth/password_file.txt
          subPath: password_file.txt
        - name: mosquitto-data
          mountPath: /mosquitto/data
        - name: mosquitto-log
          mountPath: /mosquitto/log
        - name: config-file
          mountPath: /.config/mosquitto/mosquitto.conf
          subPath: mosquitto.conf         
      securityContext:
        runAsNonRoot: true
        fsGroup: 1
        runAsGroup: 1000
        runAsUser: 1000
        supplementalGroups:
        - 1    
      volumes:
      - name: config-file
        configMap:
          name: mosquitto-config
      - name: password-file
        configMap:
          name: mosquitto-password        
      - name: mosquitto-data
        emptyDir: {}
      - name: mosquitto-log
        emptyDir: {}   

service.yml

kind: Service
metadata:
  name: chirpstack-mosquitto
  namespace: 186215-poc  
spec:
  type: ClusterIP
  ports:
    - name: mqtt 
      port: 1883
      targetPort: 1883
      protocol: TCP  
  selector:
    app: chirpstack-mosquitto    

2 Answers 2

2

mosquitto/configmap.yaml:

apiVersion: v1
kind: ConfigMap
metadata:
  name: mosquitto-config
data:
  mosquitto.conf: |-
    # Ip/hostname to listen to.
    # If not given, will listen on all interfaces
    #bind_address

    # Port to use for the default listener.
    port 1883

    # Allow anonymous users to connect?
    # If not, the password file should be created
    allow_anonymous true

    # The password file.
    # Use the `mosquitto_passwd` utility.
    # If TLS is not compiled, plaintext "username:password" lines bay be used
    # password_file /mosquitto/config/passwd

mosquitto/deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mosquitto
spec:
  selector:
    matchLabels:
      app: mosquitto
  template:
    metadata:
      labels:
        app: mosquitto
    spec:
      containers:
      - name: mosquitto
        image: eclipse-mosquitto:2.0
        resources:
          requests:
            cpu: "50m"
          limits:
            memory: "128Mi"
            cpu: "500m"
        ports:
        - containerPort: 1883
        volumeMounts:
            - name: mosquitto-config
              mountPath: /mosquitto/config/mosquitto.conf
              subPath: mosquitto.conf
      volumes:
        - name: mosquitto-config
          configMap:
            name: mosquitto-config

mosquitto/service.yaml:

apiVersion: v1
kind: Service
metadata:
  name: mosquitto
spec:
  selector:
    app: mosquitto
  ports:
  - port: 1883
    targetPort: 1883

now:

$ kubectl apply -f mosquitto/
$ kubectl get pods,deployments,services -o wide
$ kubectl logs -l app=gateway-bridge -f --all-containers 
1

Follow these steps:

  1. git clone https://github.com/halkeye-helm-charts/mosquitto.git

  2. Modify values.yaml file, adding NodePort or LoadBalancer and enabling the storageClass.

    service:
       type: NodePort
    
    persistence:
       storageClass: "oci-bv"
    
  3. Deploy through helm chart: helm install mosquitto --generate-name

  4. See the mosquitto pod logs: kubectl logs pod/mosquitto-service-name. E.g.:

    enter image description here

  5. Test the service:

    Subscriber:

    docker run -it --rm --name mqtt-subscriber efrecon/mqtt-client sub -h ip_address -p port -t "/#" 
    

    Publisher:

    docker run -it --rm --name mqtt-publisher efrecon/mqtt-client pub -h ip- address -m "SOOntestMessage" -p port -t "/test"
    
  6. You should receive messages on the subscriber:

    enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.