Volume Write Permissions Volume Write Permissions kubernetes kubernetes

Volume Write Permissions


When you have to run process inside container as non-root user and you mount a volume to pod. But the volume have root:root permission.

To give access to specific user initContainer is one way, like following

initContainers:- name: volume-mount-permission  image: busybox  command: ["sh", "-c", "chmod 775 /workspace/projects && chown -R <user> /workspace/projects"]  volumeMounts:  -name: workspace   mountPath: /workspace/projects

You can also use security context. Create user and group, add user to the group in Dockerfile and set following in spec

spec:  securityContext:    runAsUser: <UID>    runAsGroup: <GID>    fsGroup: <GID>