<p>I am spinning up a Pod (comes up with Non Root user) that needs to write data to a volume. The volume comes from a PVC.</p>

<p>The pod definition is simple</p>

<pre><code>kind: Pod
apiVersion: v1
metadata:
  name: task-pv-pod
spec:
  volumes:
    - name: task-pv-storage
      persistentVolumeClaim:
       claimName: test-pvc
  containers:
    - name: task-pv-container
      image: jnlp/jenkins-slave:latest
      command: ["/bin/bash"]
      args: ["-c", "sleep 500"]
      ports:
        - containerPort: 80
          name: "http-server"
      volumeMounts:
        - mountPath: "/usr/share/nginx/html"
          name: task-pv-storage
</code></pre>

<p>When I <code>exec</code> into the Pod and try to write into <code>/usr/share/nginx/html</code></p>

<p>I get</p>

<pre><code>jenkins@task-pv-pod:/usr/share/nginx/html$ touch test
touch: cannot touch ‘test’: Permission denied
</code></pre>

<p>Looking at the permissions of the directory</p>

<pre><code>jenkins@task-pv-pod:~$ ls -ld /usr/share/nginx/html
drwxr-xr-x 3 root root 4096 Mar 29 15:52 /usr/share/nginx/html
</code></pre>

<p>Its clear that ONLY root user can write to <code>/usr/share/nginx/html</code> but thats not what I want.</p>

<p>Is there a way to change the permissions for mounted volumes ?</p>

<p>A security context defines privilege and access control settings for a Pod or Container.          Just try <a href="https://kubernetes.io/docs/tasks/configure-pod-container/security-context" rel="nofollow noreferrer">securityContext</a>:  </p>

<pre><code>kind: Pod
apiVersion: v1
metadata:
  name: task-pv-pod
spec:
  securityContext:
    fsGroup: $jenkins_uid
  volumes:
    - name: task-pv-storage
      persistentVolumeClaim:
       claimName: test-pvc
...
</code></pre>
