<p>I am using Kubernetes yaml to mount a volume.
I know I can set the mount folder to be for a specific group using this configuration:</p>
<pre><code>  securityContext:
    fsGroup: 999
</code></pre>
<p>but no where I can find a way to also set user ownership and not just the group.</p>
<p>When I access the container folder to check ownership, it is root.</p>
<p>Anyway to do so via kubernetes Yaml?
I would expect <em>fsUser: 999</em> for example, but there is no such thing. :/</p>

toto
<p>There is no way to set the <code>UID</code> using the definition of Pod but you can use an <code>initContainer</code> with the same <code>volumeMount</code> as the main container to set the required permissions.</p>
<p>It is handy in cases like yours where user ownership needs to be set to a non root value.</p>
<p>Here is a sample configuration (change it as per your need):</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: security-context-demo
spec:
  volumes:
  - name: sec-ctx-vol
    emptyDir: {}
  containers:
  - name: sec-ctx-demo
    image: busybox
    command: [ &quot;sh&quot;, &quot;-c&quot;, &quot;sleep 1h&quot; ]
    volumeMounts:
    - name: sec-ctx-vol
      mountPath: /data/demo
    securityContext:
      allowPrivilegeEscalation: false
  initContainers:
  - name: volume-mount-hack
    image: busybox
    command: [&quot;sh&quot;, &quot;-c&quot;, &quot;chown -R 999:999 /data/demo&quot;]
    volumeMounts:
    - name: sec-ctx-vol
      mountPath: /data/demo
</code></pre>
<p><a href="https://i.stack.imgur.com/Sm6Ay.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Sm6Ay.png" alt="Permissions would end up looking like this" /></a></p>
