title: How to define the uid, gid of a mounted volume in Pod
body: <p>This is a question in our production environment. We use Kubernetes to deploy our application through Pods. The Pods may need some storage to store files. </p>
  
  <p>We use 'Persistent Volume' and 'Persistent Volume Claim' to present the real backend storage server. Currently, the real back storage server is 'NFS'. But the 'NFS' is not controlled by us and we cannot change the NFS configuration.</p>
  
  <p>Every time, the uid and gid of the volume mount into the Pod is always 'root root'. But the process in the Pod is running as a non-root user, the process cannot read/write the mounted volume.
  What our current solution is that we define an initContainer which run as root and use command 'chown [udi] [gid] [folder]' to change the ownership. There is a limitation that the ininContainer must be run as root.</p>
  
  <p>For now, we are trying to deploy our application on Openshift. By default, all the Pods(containers) cannot be run as root. Otherwise, the Pod is failed to create.</p>
  
  <p>So my question is that a k8s way or Openshift way to define/change the uid and gid of the mounted volume.
  I have tried <code>mountOptions</code> which in talked about in <a href="https://stackoverflow.com/questions/51390789/kubernetes-persistent-volume-claim-mounted-with-wrong-gid">Kubernetes Persistent Volume Claim mounted with wrong gid</a><br>
  <code>mountOptions: #these options
    - uid=1000
    - gid=1000</code></p>
  
  <p>But failed with the below error message. Seems that the NFS server does not support the uid and gid parameters.</p>
  
  <pre><code>Warning  FailedMount  11s  kubelet, [xxxxx.net]  MountVolume.SetUp failed for volume "nfs-gid-pv" : mount failed: exit status 32 Mounting command: systemd-run
  Mounting arguments: --description=Kubernetes transient mount for /opt/kubernetes/data/kubelet/pods/3c75930a-d3f7-4d55-9996-4d10dcac9549/volumes/kubernetes.io~nfs/nfs-gid-pv --scope -- mount -t nfs -o gid=1999,uid=1999 shc-sma-cd74.hpeswlab.net:/var/vols/itom/itsma/tzhong /opt/kubernetes/data/kubelet/pods/3c75930a-d3f7-4d55-9996-4d10dcac9549/volumes/kubernetes.io~nfs/nfs-gid-pv
  Output: Running scope as unit run-22636.scope.
  mount.nfs: an incorrect mount option was specified
    Warning  FailedMount  7s  kubelet, [xxxxx.net]  MountVolume.SetUp failed for volume "nfs-gid-pv" : mount failed: exit status 32
  Mounting command: systemd-run
  Mounting arguments: --description=Kubernetes transient mount for /opt/kubernetes/data/kubelet/pods/3c75930a-d3f7-4d55-9996-4d10dcac9549/volumes/kubernetes.io~nfs/nfs-gid-pv --scope -- mount -t nfs -o gid=1999,uid=1999 shc-sma-cd74.hpeswlab.net:/var/vols/itom/itsma/tzhong /opt/kubernetes/data/kubelet/pods/3c75930a-d3f7-4d55-9996-4d10dcac9549/volumes/kubernetes.io~nfs/nfs-gid-pv
  Output: Running scope as unit run-22868.scope.
  mount.nfs: an incorrect mount option was specified
  </code></pre>