<p>I am working on bringing up Eclipse mosquitto broker docker image as a kubernetes container with the below YAML configuration. However, I am unable to have any sort of logging working for this broker, to enable some debugging. Is there a way to pass &quot;command&quot; to ask this docker image to the configuration file provided instead of using the default one ? Can anyone share a commonly used YAML file for starting the broker with persistance/volume/logging capabilities ?</p>
<pre><code> apiVersion: v1
 kind: Pod
 metadata:
   name: infra-pod
   labels:
     app: infra
 spec:
   containers:
     - name: mosquitto-broker
       image: eclipse-mosquitto
       ports:
         - containerPort: 1883
         - containerPort: 8883
</code></pre>

Jimmy
<p>Below you will find an example how volumes are mounted for mosquitto deployment.  Please before you start trying them out visit kubernetes documents about <a href="https://kubernetes.io/docs/concepts/storage/volumes/" rel="nofollow noreferrer">volumes</a> to understand a bit more how they are used and which one is suitable for your environment.</p>
<pre class="lang-yaml prettyprint-override"><code>        volumeMounts:
        - name: mosquitto
          mountPath: /srv/mqtt/config
        - name: localtime
          mountPath: /etc/localtime
        - name: mosquitto-data
          mountPath: /srv/mqtt/data
        - name: mosquitto-log
          mountPath: /srv/mqtt/log
</code></pre>
<pre class="lang-yaml prettyprint-override"><code>      volumes:
      - name: mosquitto
        persistentVolumeClaim:
          claimName: mosquitto
      - name: mosquitto-data
        persistentVolumeClaim:
          claimName: mosquitto-data
      - name: mosquitto-log
        persistentVolumeClaim:
          claimName: mosquitto-log
      - name: localtime
        hostPath:
          path: /home/test
</code></pre>
<p>To provide some custom config you have <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/" rel="nofollow noreferrer">configure your pod to use Kubernetes configMap</a>.What you are doing below is to add ConfigMap name under the <code>volumes</code> section of the Pod specification. This adds the ConfigMap data to the directory specified as <code>volumeMounts.mountPath</code>.</p>
<pre class="lang-yaml prettyprint-override"><code>      volumeMounts:
      - name: password-file
        mountPath: /.config/mosquitto/auth/password_file.txt
        subPath: password_file.txt
      - name: config-file
        mountPath: /.config/mosquitto/mosquitto.conf
        subPath: mosquitto.conf 
</code></pre>
<pre class="lang-yaml prettyprint-override"><code>   ----
      volumes:
      - name: config-file
        configMap:
          name: mosquitto-config
      - name: password-file
        configMap:
          name: mosquitto-password        
---
</code></pre>
<p>In the example above there is another field used called <code>subPath</code> which is used to mount specified file into pod directory. This is being used to avoid mouting volume and top of the existing directory.  You can more about <a href="https://dev.to/joshduffney/kubernetes-using-configmap-subpaths-to-mount-files-3a1i" rel="nofollow noreferrer">here</a>.</p>
<p>Please note that those yamls are purely informational and serves as an example how to pass config and mount volumes. You will have to adjust them to you needs.</p>
