I'm trying to set up my mosquitto server inside a Kubernetes cluster and somehow I'm getting the following error and I can't figure out why. Could someone help me?
Error:
1551171948: mosquitto version 1.4.10 (build date Wed, 13 Feb 2019 00:45:38 +0000) starting
1551171948: Config loaded from /etc/mosquitto/mosquitto.conf.
1551171948: |-- *** auth-plug: startup
1551171948: |-- ** Configured order: http
1551171948: |-- with_tls=false
1551171948: |-- getuser_uri=/api/mosquitto/users
1551171948: |-- superuser_uri=/api/mosquitto/admins
1551171948: |-- aclcheck_uri=/api/mosquitto/permissions
1551171948: |-- getuser_params=(null)
1551171948: |-- superuser_params=(null)
1551171948: |-- aclcheck_paramsi=(null)
1551171948: Opening ipv4 listen socket on port 1883.
1551171948: Error: Cannot assign requested address
Mosquitto.conf:
allow_duplicate_messages false
connection_messages true
log_dest stdout stderr
log_timestamp true
log_type all
persistence false
listener 1883 mosquitto
allow_anonymous true
# Public
# listener 8883 0.0.0.0
listener 9001 0.0.0.0
protocol websockets
allow_anonymous false
auth_plugin /usr/lib/mosquitto-auth-plugin/auth-plugin.so
auth_opt_backends http
auth_opt_http_ip 127.0.0.1
auth_opt_http_getuser_uri /api/mosquitto/users
auth_opt_http_superuser_uri /api/mosquitto/admins
auth_opt_http_aclcheck_uri /api/mosquitto/permissions
auth_opt_acl_cacheseconds 1
auth_opt_auth_cacheseconds 0
Kubernetes.yaml:
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: mosquitto
spec:
replicas: 1
template:
metadata:
labels:
app: mosquitto
spec:
imagePullSecrets:
- name: abb-login
containers:
- name: mosquitto
image: ****mosquitto:develop
imagePullPolicy: Always
ports:
- containerPort: 9001
protocol: TCP
- containerPort: 1883
protocol: TCP
- containerPort: 8883
protocol: TCP
resources: {}
---
apiVersion: v1
kind: Service
metadata:
name: mosquitto
spec:
ports:
- name: "9001"
port: 9001
targetPort: 9001
protocol: TCP
- name: "1883"
port: 1883
targetPort: 1883
protocol: TCP
- name: "8883"
port: 8883
targetPort: 8883
protocol: TCP
selector:
app: mosquitto
The problem is with the listener on port 1883, this can be determined because the log hasn't got to the 9001 listener yet.
The problem is most likely because mosquitto can not resolve the IP address of the hostname mosquitto
. When passing a hostname the name must resolve to a valid IP address. The same problem has been discussed in this recent answer. It could also be that mosquitto
is resolving to an address that is not bound to any of the interfaces on the actual machine (e.g. if Address Translation is being used).
Also for the 9001 listener rather than passing 0.0.0.0
you can just not include a bind address and the default is to listen on all interfaces.