title: Kubernetes Permission denied for mounted nfs volume
body: <p>The following is the k8s definition used:</p>
  
  <pre><code>apiVersion: v1
  kind: PersistentVolumeClaim
  metadata:
    name: nfs-pv-provisioning-demo
    labels:
      demo: nfs-pv-provisioning
  spec:
    accessModes: [ "ReadWriteOnce" ]
    resources:
      requests:
        storage: 200Gi
  ---
  apiVersion: v1
  kind: ReplicationController
  metadata:
    name: nfs-server
  spec:
    securityContext:
      runAsUser: 1000
      fsGroup: 2000
    replicas: 1
    selector:
      role: nfs-server
    template:
      metadata:
        labels:
          role: nfs-server
      spec:
        containers:
        - name: nfs-server
          image: k8s.gcr.io/volume-nfs:0.8
          ports:
            - name: nfs
              containerPort: 2049
            - name: mountd
              containerPort: 20048
            - name: rpcbind
              containerPort: 111
          securityContext:
            privileged: true
          volumeMounts:
            - mountPath: /exports
              name: mypvc
        volumes:
          - name: mypvc
            persistentVolumeClaim:
              claimName: nfs-pv-provisioning-demo
  ---
  kind: Service
  apiVersion: v1
  metadata:
    name: nfs-server
  spec:
    ports:
      - name: nfs
        port: 2049
      - name: mountd
        port: 20048
      - name: rpcbind
        port: 111
    selector:
      role: nfs-server
  ---
  apiVersion: v1
  kind: PersistentVolume
  metadata:
    name: nfs
  spec:
    capacity:
      storage: 1Gi
    accessModes:
      - ReadWriteMany
    nfs:
      # FIXME: use the right IP
      server: nfs-server
      path: "/"
  ---
  apiVersion: v1
  kind: PersistentVolumeClaim
  metadata:
    name: nfs
  spec:
    accessModes:
      - ReadWriteMany
    storageClassName: ""
    resources:
      requests:
        storage: 1Gi
  ---
  # This mounts the nfs volume claim into /mnt and continuously
  # overwrites /mnt/index.html with the time and hostname of the pod.
  
  apiVersion: v1
  kind: ReplicationController
  metadata:
    name: nfs-busybox
  spec:
    securityContext:
      runAsUser: 1000
      fsGroup: 2000
    replicas: 2
    selector:
      name: nfs-busybox
    template:
      metadata:
        labels:
          name: nfs-busybox
      spec:
        containers:
        - image: busybox
          command:
            - sh
            - -c
            - 'while true; do date &gt; /mnt/index.html; hostname &gt;&gt; /mnt/index.html; sleep $(($RANDOM % 5 + 5)); done'
          imagePullPolicy: IfNotPresent
          name: busybox
          volumeMounts:
            # name must match the volume name below
            - name: nfs
              mountPath: "/mnt"
        volumes:
        - name: nfs
          persistentVolumeClaim:
            claimName: nfs
  </code></pre>
  
  <p>Now /mnt directory in nfs-busybox should have 2000 as gid(as per <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/" rel="noreferrer">docs</a>). But it still have  root and root as user and group. Since application is running with 1000/2000 its not able to create any logs or data in /mnt directory. </p>
  
  <p>chmod might solve the issue, but it looks like work around. Is there any permenant solution for this?</p>
  
  <p>Observations: If i replace nfs with some other PVC its working fine as told in <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/" rel="noreferrer">docs</a>.</p>