<p>I'm trying to set up RabbitMQ on Minikube using the <a href="https://www.rabbitmq.com/kubernetes/operator/operator-overview.html" rel="nofollow noreferrer">RabbitMQ Cluster Operator</a>:</p>
<p>When I try to attach a persistent volume, I get the following error:</p>
<pre><code>$ kubectl logs -f rabbitmq-rabbitmq-server-0

Configuring logger redirection
20:04:40.081 [warning] Failed to write PID file &quot;/var/lib/rabbitmq/mnesia/rabbit@rabbitmq-rabbitmq-server-0.rabbitmq-rabbitmq-headless.default.pid&quot;: permission denied
20:04:40.264 [error] Failed to create Ra data directory at '/var/lib/rabbitmq/mnesia/rabbit@rabbitmq-rabbitmq-server-0.rabbitmq-rabbitmq-headless.default/quorum/rabbit@rabbitmq-rabbitmq-server-0.rabbitmq-rabbitmq-headless.default', file system operation error: enoent
20:04:40.265 [error] Supervisor ra_sup had child ra_system_sup started with ra_system_sup:start_link() at undefined exit with reason {error,&quot;Ra could not create its data directory. See the log for details.&quot;} in context start_error
20:04:40.266 [error] CRASH REPORT Process &lt;0.247.0&gt; with 0 neighbours exited with reason: {error,&quot;Ra could not create its data directory. See the log for details.&quot;} in ra_system_sup:init/1 line 43
20:04:40.267 [error] CRASH REPORT Process &lt;0.241.0&gt; with 0 neighbours exited with reason: {{shutdown,{failed_to_start_child,ra_system_sup,{error,&quot;Ra could not create its data directory. See the log for details.&quot;}}},{ra_app,start,[normal,[]]}} in application_master:init/4 line 138
{&quot;Kernel pid terminated&quot;,application_controller,&quot;{application_start_failure,ra,{{shutdown,{failed_to_start_child,ra_system_sup,{error,\&quot;Ra could not create its data directory. See the log for details.\&quot;}}},{ra_app,start,[normal,[]]}}}&quot;}
Kernel pid terminated (application_controller) ({application_start_failure,ra,{{shutdown,{failed_to_start_child,ra_system_sup,{error,&quot;Ra could not create its data directory. See the log for details.&quot;}

Crash dump is being written to: erl_crash.dump...
</code></pre>
<p>The issue is that RabbitMQ is not able to set up its data files in the data directory <code>/var/lib/rabbitmq/mnesia</code> due to a lack of permission.</p>
<p>My initial guess was that I needed to specify the data directory as a volumeMount, but that doesn't seem to be configurable according to the <a href="https://www.rabbitmq.com/kubernetes/operator/using-operator.html" rel="nofollow noreferrer">documentation</a>.</p>
<p>RabbitMQ's <a href="https://www.rabbitmq.com/kubernetes/operator/troubleshooting-operator.html" rel="nofollow noreferrer">troubleshooting</a> documentation on persistence results in a <a href="https://www.rabbitmq.com/using-cluster-operator.html#persistence" rel="nofollow noreferrer">404</a>.</p>
<p>I tried to find other resources online with the same problem but none of them were using the RabbitMQ Cluster Operator. I plan on following that route if I'm not able to find a solution but I really would like to solve this issue somehow.</p>
<p>Does anyone have any ideas?</p>
<p>The setup that I have is as follows:</p>
<pre><code>apiVersion: rabbitmq.com/v1beta1
kind: RabbitmqCluster
metadata:
  name: rabbitmq
spec:
  replicas: 1
  service:
    type: NodePort
  persistence:
    storageClassName: local-storage
    storage: 20Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: rabbitmq-pvc
spec:
  storageClassName: local-storage
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi

---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: rabbitmq-pv
spec:
  storageClassName: local-storage
  accessModes:
    - ReadWriteOnce
  capacity:
    storage: 20Gi
  hostPath:
    path: /mnt/app/rabbitmq
    type: DirectoryOrCreate
</code></pre>
<p>To reproduce this issue on minikube:</p>
<ol>
<li>Install the rabbitmq operator:</li>
</ol>
<pre class="lang-sh prettyprint-override"><code>kubectl apply -f &quot;https://github.com/rabbitmq/cluster-operator/releases/latest/download/cluster-operator.yml&quot;
</code></pre>
<ol start="2">
<li>Apply the manifest file above</li>
</ol>
<pre><code>kubectl apply -f rabbitmq.yml
</code></pre>
<ol start="3">
<li><p>Running <code>kubectl get po</code> displays a pod named <code>rabbitmq-rabbitmq-server-0</code>.</p>
</li>
<li><p>Running <code>kubectl logs -f rabbitmq-rabbitmq-server-0</code> to view the logs displays the above error.</p>
</li>
</ol>

W.K.S
<p>As I alread suggested in comments, you can solve it running:</p>
<pre><code>minikube ssh -- sudo chmod g+w /mnt/app/rabbitmq/ 
</code></pre>
<hr />
<p>Answering to your question:</p>
<blockquote>
<p>Is there a way I can add that to my manifest file rather than having to do it manually?</p>
</blockquote>
<p>You can override the rabbitmq statefulset manifest fields to change last line in initContainer command script from <code> chgrp 999 /var/lib/rabbitmq/mnesia/</code> to this: <code>chown 999:999 /var/lib/rabbitmq/mnesia/</code>.</p>
<p>Complete RabbitmqCluster yaml manifest looks like following:</p>
<pre><code>apiVersion: rabbitmq.com/v1beta1
kind: RabbitmqCluster
metadata:
  name: rabbitmq
spec:
  replicas: 1
  service:
    type: NodePort
  persistence:
    storageClassName: local-storage
    storage: 20Gi
  override:
    statefulSet:
      spec:
        template:
          spec:
            containers: []
            initContainers:
            - name: setup-container
              command:
              - sh
              - -c
              - cp /tmp/rabbitmq/rabbitmq.conf /etc/rabbitmq/rabbitmq.conf &amp;&amp; chown 999:999
                /etc/rabbitmq/rabbitmq.conf &amp;&amp; echo '' &gt;&gt; /etc/rabbitmq/rabbitmq.conf ; cp /tmp/rabbitmq/advanced.config
                /etc/rabbitmq/advanced.config &amp;&amp; chown 999:999 /etc/rabbitmq/advanced.config
                ; cp /tmp/rabbitmq/rabbitmq-env.conf /etc/rabbitmq/rabbitmq-env.conf &amp;&amp; chown
                999:999 /etc/rabbitmq/rabbitmq-env.conf ; cp /tmp/erlang-cookie-secret/.erlang.cookie
                /var/lib/rabbitmq/.erlang.cookie &amp;&amp; chown 999:999 /var/lib/rabbitmq/.erlang.cookie
                &amp;&amp; chmod 600 /var/lib/rabbitmq/.erlang.cookie ; cp /tmp/rabbitmq-plugins/enabled_plugins
                /etc/rabbitmq/enabled_plugins &amp;&amp; chown 999:999 /etc/rabbitmq/enabled_plugins
                ; chown 999:999 /var/lib/rabbitmq/mnesia/ # &lt;- CHANGED THIS LINE
</code></pre>
