<p>I'd like to expose default port (1883) and WS port (9001) of MQTT server on an Azure Kubernetes Cluster. </p>

<p>Anyway here is the deployement I currently wrote : </p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: mqtt-server
spec: 
  replicas: 1
  selector: 
    matchLabels: 
      app: mqtt-server
  template: 
    metadata: 
      labels: 
        app: mqtt-server
        type: backend 
    spec: 
      containers: 
        - name: mqtt-server
          image: eclipse-mosquitto:1.5.4
          resources: 
            requests:
              cpu: 250m
              memory: 256Mi
          ports:
            - name: mqtt-dflt-port
              containerPort: 1883
            - name: mqtt-ws-port
              containerPort: 9001
---
apiVersion: v1
kind: Service
metadata:
  name: mqtt-server-service
spec:
  selector:
    app: mqtt-server
  type: LoadBalancer
  ports:
  - name: mqtt-dflt-port
    protocol: TCP
    port: 1883
    targetPort: 1883
  - name: mqtt-ws-port
    protocol: TCP
    port: 1884
    targetPort: 9001</code></pre>
</div>
</div>
</p>

<p>And when I deploy it, everything is fine but the MQTT broker is unreachable and my service is described like that : </p>

<pre><code>mqtt-server-service   LoadBalancer   10.0.163.167   51.143.170.64   1883:32384/TCP,1884:31326/TCP   21m
</code></pre>

<p>Why is the 1883/9001 port aren't forwarded like it should be ? </p>

NeitoFR
<p>First, make sure you’re connecting to the service’s cluster IP from within the
cluster, not from the outside.
Don’t bother pinging the service IP to figure out if the service is accessible
(remember, the service’s cluster IP is a virtual IP and pinging it will never work).
If you’ve defined a readiness probe, make sure it’s succeeding; otherwise the</p>

<p>pod won’t be part of the service.
To confirm that a pod is part of the service, examine the corresponding End-
points object with kubectl get endpoints .
If you’re trying to access the service through its FQDN or a part of it (for exam-
ple, myservice.mynamespace.svc.cluster.local or myservice.mynamespace) and
it doesn’t work, see if you can access it using its cluster IP instead of the FQDN.
Check whether you’re connecting to the port exposed by the service and not
the target port.
Try connecting to the pod IP directly to confirm your pod is accepting connec-
tions on the correct port.
If you can’t even access your app through the pod’s IP, make sure your app isn’t
only binding to localhost.</p>
