<p>I have a rabbit mq pod and I configured to use a persistence storage incase of pod restart/deletion by mounting a volume.</p>
<p>I configured everything but not able to get through this error:</p>
<pre><code>/usr/lib/rabbitmq/bin/rabbitmq-server: 42: 
/usr/lib/rabbitmq/bin/rabbitmq-server: 
cannot create /var/lib/rabbitmq/mnesia/rabbit@reana-message-broker-5f45f797ff-cs79m.pid: 
Permission denied
</code></pre>
<p>Here're my config file and deployment app for kubernetes</p>
<ol>
<li><code>Dockerfile</code></li>
</ol>
<pre><code>FROM ubuntu:16.04
# hadolint ignore=DL3009
RUN apt-get update
# hadolint ignore=DL3008
RUN apt-get -y install --no-install-recommends rabbitmq-server
RUN apt-get -y autoremove &amp;&amp; apt-get -y clean
# hadolint ignore=DL3001
RUN service rabbitmq-server start
COPY start.sh /start.sh
RUN chmod 755 ./start.sh
EXPOSE 5672
EXPOSE 15672
CMD [&quot;/start.sh&quot;, &quot;test&quot;, &quot;1234&quot;]
</code></pre>
<ol start="2">
<li><code>start.sh</code></li>
</ol>
<pre><code>#!/bin/sh
cat &gt; /etc/rabbitmq/rabbitmq.conf &lt;&lt;EOF
listeners.tcp.default = 5672

default_user = &lt;&lt;&quot;$1&quot;&gt;&gt;
default_pass = &lt;&lt;&quot;$2&quot;&gt;&gt;
EOF
rabbitmq-server
</code></pre>
<ol start="3">
<li><code>rabbitmq.yaml</code></li>
</ol>
<pre><code>---
apiVersion: v1
kind: Service
metadata:
  name: message-broker
  namespace: {{ .Release.Namespace }}
spec:
  ports:
   - port: 5672
     targetPort: 5672
     name: &quot;tcp&quot;
     protocol: TCP
   - port: 15672
     targetPort: 15672
     name: &quot;management&quot;
     protocol: TCP
  selector:
    app: message-broker
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: message-broker
  namespace: {{ .Release.Namespace }}
spec:
  replicas: 1
  selector:
    matchLabels:
      app: message-broker
  template:
    metadata:
      labels:
        app: message-broker
    spec:
      containers:
      - name: message-broker
        image: {{ .Values.message_broker.image }}
        imagePullPolicy: {{ .Values.components.message_broker.imagePullPolicy }}
        ports:
        - containerPort: 5672
          name: tcp
        - containerPort: 15672
          name: management
        volumeMounts:
        - name: data
          mountPath: /var/lib/rabbitmq/mnesia
        env:
        - name: RABBITMQ_DEFAULT_PASS
          valueFrom:
            secretKeyRef:
              name: rabbitmq-secrets
              key: password # password = root
        - name: RABBITMQ_DEFAULT_USER
          valueFrom:
            secretKeyRef:
              name: rabbitmq-secrets
              key: user # user = root
      ...
      nodeSelector:
      ....
      volumes:
      - name: data
        hostPath:
          path: /var/test/rabbitmq
</code></pre>
<p>Let me know what I might be missing. :)</p>

ParthS007
<p>The volume you mounted in <code>/var/lib/rabbitmq/mnesia</code> is owned by root.</p>
<p>The rabbitmq process is running as <code>rabbitmq</code> user and doesn't have write access to this directory.</p>
<p>In your <code>start.sh</code> add:</p>
<pre><code>chown rabbitmq:rabbitmq /var/lib/rabbitmq/mnesia
</code></pre>
<p>before starting the rabbitmq-server process.</p>
