<p>When  I using this command in kubernetes v1.18 jenkins's master pod to mount a nfs file system:</p>
<pre><code>root@jenkins-67fff76bb6-q77xf:/# mount -t nfs -o v4 192.168.31.2:/infrastructure/jenkins-share-workspaces /opt/jenkins
mount: permission denied
root@jenkins-67fff76bb6-q77xf:/# 
</code></pre>
<p>why it shows permission denied althrough I am using root user? when I using this command in another machine(not in docker), it works fine, shows the server side works fine. this is my kubernetes jenkins master pod secure text config in yaml:</p>
<pre><code>securityContext:
        runAsUser: 0
        fsGroup: 0
</code></pre>
<p>today I tried another kubernetes pod and mount nfs file system and throw the same error. It seems mount NFS from host works fine, and mount from kubernetes pod have a perssion problem. Why would this happen? the NFS is works fine by PVC binding PV in this kubernetes pod, why it mount from docker failed? I am confusing.</p>

<p>There are two ways to mount nfs volume to a pod</p>
<p>First (directly in pod spec):</p>
<pre><code>kind: Pod
apiVersion: v1
metadata:
  name: pod-using-nfs
spec:
  volumes:
    - name: nfs-volume
      nfs: 
        server: 192.168.31.2
        path: /infrastructure/jenkins-share-workspaces
  containers:
    - name: app
      image: example
      volumeMounts:
        - name: nfs-volume
          mountPath: /var/nfs
</code></pre>
<p>Second (creating persistens nfs volume and volume claim):</p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs
spec:
  capacity:
    storage: 1Mi
  accessModes:
    - ReadWriteMany
  nfs:
    server: 192.168.31.2
    path: &quot;/infrastructure/jenkins-share-workspaces&quot;

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nfs
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: &quot;&quot;
  resources:
    requests:
      storage: 1Mi
  volumeName: nfs

---
kind: Pod
apiVersion: v1
metadata:
  name: pod-using-nfs
spec:
  containers:
    - name: app
      image: example
      volumeMounts:
        - name: nfs
          mountPath: /opt/jenkins
  volumes:
    - name: nfs
      persistentVolumeClaim:
        claimName: nfs
</code></pre>
<p>EDIT:</p>
<p>The solution above is prefered one, but if you reallly need to use mount in container you need to add capabilities to the pod:</p>
<pre><code>spec:
  containers:
  - securityContext:
      capabilities:
        add: [&quot;SYS_ADMIN&quot;]
</code></pre>
