<p>In kubernetes I can use a <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#persistentvolumeclaims" rel="noreferrer">PersistentVolumeClaim</a> to create some storage, which I can later mount in some container.</p>

<p>However if the user in the container is not root, that user will not be able to access that directory because it is owned by root.</p>

<p>What is the right way to access such a volume? (I did not find any user/permission options both when creating and mounting that volume.)</p>

<p>First, find out the UID number your process is running as.</p>
<p>Then you can tell Kubernetes to chown (sort of) the mount point of the volume for your pod by adding <a href="https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#security-context" rel="nofollow noreferrer"><code>.spec.securityContext.fsGroup</code></a>:</p>
<pre><code>spec:
  ...
  securityContext:
    fsGroup: 2000
</code></pre>
<blockquote>
<p><code>fsGroup</code>: integer: A special supplemental group that applies to all containers in a pod. Some volume types allow the Kubelet to change the ownership of that volume to be owned by the pod: 1. The owning GID will be the FSGroup 2. The setgid bit is set (new files created in the volume will be owned by FSGroup) 3. The permission bits are OR'd with rw-rw---- If unset, the Kubelet will not modify the ownership and permissions of any volume.</p>
</blockquote>
