How to change permission of mapped volume in kubernetes

5/17/2019

I try to mount a folder that is non-root user(xxxuser) at kubernetes and I use hostPath for mounting. But whenever container is started, it is mounted with user (1001) not xxxuser. It is always started with user (1001). How can I mount this folder with xxxuser ?

There is many types of volumes but I use hostPath. Before started; I change folder user and group with chown and chgrp commands. And then; mounted this folder as volume. Container started and I checked user of folder but it always user (1001). Such as;

drwxr-x---. 2 1001 1001 70 May 3 14:15 configutil/

volumeMounts:
        - name: configs
          mountPath: /opt/KOBIL/SSMS/home/configutil
      volumes:
      - name: configs
        hostPath:
          path: /home/ssmsuser/configutil
          type: Directory

drwxr-x---. 2 xxxuser xxxuser 70 May 3 14:15 configutil/

-- O.Kaplan
kubernetes

2 Answers

5/17/2019

You may specify the desired owner of mounted volumes using following syntax:

spec:
  securityContext:
    fsGroup: 2000
-- Vasily Angapov
Source: StackOverflow

5/20/2019

I try what you have recomend but my problem is still continue. I add below line to my yaml file:

spec:
      securityContext:
        runAsUser: 999
        runAsGroup: 999
        fsGroup: 999

I use 999 because I use 999 inside my Dockerfile. Such as;

RUN groupadd -g 999 ssmsuser && \
useradd -r -u 999 -g ssmsuser ssmsuser
USER ssmsuser
-- O.Kaplan
Source: StackOverflow