<p>I'm trying to deploy a MongoDB pod on a minikube instance.<br />
I've mounted a local directory on the minikube machine and I want MongoDB to write data in this directory.</p>
<p>Minikube is started using this command line:</p>
<pre><code>minikube start --mount --mount-string=/home/minikube:/data/host
</code></pre>
<p>My <code>mongo-deploy.yaml</code> looks like the following</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata: 
  name: mongodb-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongodb
  template:
    metadata:
      labels:
        app: mongodb
    spec:
      containers:
        - name: mongodb
          image: mongo
          volumeMounts:
            - name: mongodb-data
              mountPath: /data/db
      volumes:
        - name: mongodb-data
          hostPath:
            path: /data/host/mongo
---
apiVersion: v1
kind: Service
metadata:
  name: mongodb-srv
spec:
  selector:
    app: mongodb
  ports:
    - name: mongodb
      protocol: TCP
      port: 27017
      targetPort: 27017
</code></pre>
<p>The problem is when the pod starts, I got this error</p>
<pre><code>{&quot;log&quot;:&quot;{\&quot;t\&quot;:{\&quot;$date\&quot;:\&quot;2021-01-17T23:27:54.524+00:00\&quot;},\&quot;s\&quot;:\&quot;E\&quot;,  \&quot;c\&quot;:\&quot;STORAGE\&quot;,  \&quot;id\&quot;:20557,   \&quot;ctx\&quot;:\&quot;initandlisten\&quot;,\&quot;msg\&quot;:\&quot;DBException in initAndListen, terminating\&quot;,\&quot;attr\&quot;:{\&quot;error\&quot;:\&quot;IllegalOperation: Attempted to create a lock file on a read-only directory: /data/db\&quot;}}\n&quot;,&quot;stream&quot;:&quot;stdout&quot;,&quot;time&quot;:&quot;2021-01-17T23:27:54.524391471Z&quot;}
</code></pre>
<p>I'm pretty sure it's all about folder permission.
I've tried to set a <code>chmod 777</code> on the local folder but it doesn't work.</p>
<p>What is the correct way to persist data from minikube in the local machine ?</p>

T00rk
<p>I encountered the same symptom. I agree with OP that it is due to ownership.</p>
<p>In the common Mongo image, UID for the MongoDB user is 999. However, inserting a command or init container did not succeed for me.</p>
<p>What <em>did</em> succeed was adding a <code>securityContext</code> annotation to the pod spec:</p>
<pre><code>securityContext:
  fsGroup: 999
</code></pre>
<p>I found that here:
<a href="https://www.edureka.co/community/35763/set-volume-mount-user-group-and-file-permissions-kubernetes" rel="nofollow noreferrer">https://www.edureka.co/community/35763/set-volume-mount-user-group-and-file-permissions-kubernetes</a></p>
<p>This seems like the way.</p>
