How to mount volume with specific UID in Kubernetes Pod?

There is no way to set the UID using the definition of Pod, but Kubernetes saves the UID of sourced volume.

So, you can set the UID by InitContainer, which launches before the main container, just add it to the containers path of the Deployment:

initContainers:
- name: volume-mount-hack
  image: busybox
  command: ["sh", "-c", "chown -R 200:200 /nexus"]
  volumeMounts:
  - name: <your nexus volume>
    mountPath: /nexus

Leave a Comment