title: NFS volumes are not persistent in kubernetes
body: <p>I'm trying to mount mongo <code>/data</code> directory on to a NFS volume in my kubernetes master machine for persisting mongo data. I see the volume is mounted successfully but I can see only <code>configdb</code> and <code>db</code> dirs but not their subdirectories. And I see the data is not even persisting in the volume. when I <code>kubectl describe &lt;my_pv&gt;</code> it shows <code>NFS (an NFS mount that lasts the lifetime of a pod)</code> </p>
  
  <p>Why is that so?</p>
  
  <p>I see in kubernetes docs stating that:</p>
  
  <blockquote>
    <p>An nfs volume allows an existing NFS (Network File System) share to be
    mounted into your pod. Unlike emptyDir, which is erased when a Pod is
    removed, the contents of an nfs volume are preserved and the volume is
    merely unmounted. This means that an NFS volume can be pre-populated
    with data, and that data can be “handed off” between pods. NFS can be
    mounted by multiple writers simultaneously.</p>
  </blockquote>
  
  <p>I'm using kubernetes version 1.8.3.</p>
  
  <p>mongo-deployment.yml:</p>
  
  <pre><code>apiVersion: apps/v1beta2
  kind: Deployment
  metadata:
    name: mongo
    labels:
      name: mongo
      app: mongo
  spec:
    replicas: 3
    selector:
      matchLabels:
        name: mongo
        app: mongo
    template:
      metadata:
        name: mongo
        labels:
          name: mongo
          app: mongo
      spec:
        containers:
          - name: mongo
            image: mongo:3.4.9
            ports:
              - name: mongo
                containerPort: 27017
                protocol: TCP
            volumeMounts:
              - name: mongovol
                mountPath: "/data"
        volumes:
        - name: mongovol
          persistentVolumeClaim:
            claimName: mongo-pvc
  </code></pre>
  
  <p>mongo-pv.yml:</p>
  
  <pre><code>apiVersion: v1
  kind: PersistentVolume
  metadata:
    name: mongo-pv
    labels:
      type: NFS
  spec:
    capacity:
      storage: 5Gi
    accessModes:
      - ReadWriteMany
    persistentVolumeReclaimPolicy: Retain
    storageClassName: slow
    mountOptions:
      - hard
      - nfsvers=4.1
    nfs:
      path: "/mongodata"
      server: 172.20.33.81
  </code></pre>
  
  <p>mongo-pvc.yml:</p>
  
  <pre><code>apiVersion: v1
  kind: PersistentVolumeClaim
  metadata:
    name: mongo-pvc
  spec:
    accessModes:
      - ReadWriteMany
    resources:
      requests:
        storage: 3Gi
    storageClassName: slow
    selector:
      matchLabels:
        type: NFS
  </code></pre>
  
  <p>The way I mounted my nfs share on my kubernetes master machine:</p>
  
  <pre><code>1) apt-get install nfs-kernel-server
  2) mkdir /mongodata
  3) chown nobody:nogroup -R /mongodata
  4) vi /etc/exports
  5) added the line "/mongodata *(rw,sync,all_squash,no_subtree_check)"
  6) exportfs -ra
  7) service nfs-kernel-server restart
  8) showmount -e ----&gt; shows the share
  </code></pre>
  
  <p>I logged into the bash of my pod and I see the directory is mounted correctly but data is not persisting in my nfs server (kubernetes master machine). </p>
  
  <p>Please help me see what I am doing wrong here.</p>