<p>I have deployed mongodb pod on kubernetes and able to connect and insert the data in database. But when the pod gets restart all my data is being lost. I have created persistentvolume also for mongodb but still the data is being lost. Below are my yamls. Can someone please someone explain what I am doing wrong here.</p>
<p>Statefulset.yaml</p>
<pre><code>---
  apiVersion: &quot;apps/v1&quot;
  kind: &quot;StatefulSet&quot;
  metadata:
     name: &quot;mongo-development&quot;
     namespace: &quot;development&quot;
  spec:
    serviceName: &quot;mongo-development&quot;
    replicas: 1
    selector:
      matchLabels:
        app: &quot;mongo-development&quot;
    template:
      metadata:
        labels:
           app: &quot;mongo-development&quot;
      spec:
        containers:
          -
            name: &quot;mongo-development&quot;
            image: &quot;mongo&quot;
            imagePullPolicy: &quot;Always&quot;
            env:
             -
                name: &quot;MONGO_INITDB_ROOT_USERNAME&quot;
                value: &quot;xxxx&quot;

             -
                name: &quot;MONGO_INITDB_ROOT_PASSWORD&quot;
                value: &quot;xxxx&quot;

            ports:
              -
                containerPort: 27017
                name: &quot;mongodb&quot;

            volumeMounts: 
              - 
                name: &quot;mongodb-persistent-storage&quot;
                mountPath: &quot;/var/lib/mongodb&quot;
        volumes: 
          - 
            name: &quot;mongodb-persistent-storage&quot;
            persistentVolumeClaim: 
              claimName: &quot;mongodb-pvc-development&quot;
</code></pre>
<p>pvc.yaml</p>
<pre><code>---
  apiVersion: &quot;v1&quot;
  kind: &quot;PersistentVolumeClaim&quot;
  metadata: 
    name: &quot;mongodb-pvc-development&quot;
    namespace: &quot;development&quot;
    labels: 
      app: &quot;mongo-development&quot;
  spec: 
    accessModes: 
      - ReadWriteOnce
    resources: 
      requests: 
        storage: 5Gi
    storageClassName: gp2

</code></pre>
<p>pv.yaml</p>
<pre><code>---
apiVersion: &quot;v1&quot;
kind: &quot;PersistentVolume&quot;
metadata:
 name: &quot;mongo-pv-development&quot;
 namespace: &quot;development&quot;
 labels:
  type: local
  app: &quot;mongo-development&quot;
spec:
  storageClassName: &quot;local-storage&quot;
  capacity:
     storage: 5Gi
  accessModes:
     - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  claimRef:
     namespace: &quot;development&quot;
     name: &quot;mongodb-pvc-development&quot;
  nfs:
     path: /mnt
     server: xxxx
</code></pre>
<p>service.yaml</p>
<pre><code>---
  apiVersion: &quot;v1&quot;
  kind: &quot;Service&quot;
  metadata: 
    name: &quot;mongo-development&quot;
    namespace: &quot;development&quot;
    labels: 
      app: &quot;mongo-development&quot;
  spec: 
    ports: 
      - 
        name: &quot;mongodb&quot;
        port: 27017
        targetPort: 27017
    clusterIP: &quot;None&quot;
    selector: 
      app: &quot;mongo-development&quot;

</code></pre>

SVD
<p>Issue got resolved the mountpath which I have defined was incorrect it should be /data/db in statefulset.yaml file</p>
