kind: Job
metadata:
name: test
spec:
ttlSecondsAfterFinished: 3600
backoffLimit: 0
template:
metadata:
annotations:
version: "1.0"
labels:
component: test
name: test
spec:
securityContext:
runAsUser: 1000
runAsGroup: 1000
fsGroup: 5000
restartPolicy: Never
initContainers:
- name: test-init
image: sampleimage:latest
volumeMounts:
- name: testvol
mountPath: /u01/subpath
command: ['sh', '-c', "whoami && cd /u01/subpath && echo 1 && mkdir -p -m 0777 folder1 && echo 2 && mkdir -p -m 0777 folder2 && echo 4 && echo done"]
containers:
- image: sampleimage:latest
imagePullPolicy: Always
name: testcontainer
resources:
requests:
cpu: 1
memory: 4G
limits:
cpu: 1
memory: 4G
volumeMounts:
- name: testvol
mountPath: /u01/subpath/folder1
subPath: folder1
- name: testvol
mountPath: /u01/subpath/folder2
subPath: folder2
command: ['sh', '-c','ls -lrt /u01 ']
volumes:
- name: testvol
persistentVolumeClaim:
claimName: testpvc```
I am trying to create a job with the above specs. the default user of folder1 and folder 2 is coming as root. How can the user of the folder be changed when a persistent volume claim is mounted to a folder with sub-paths as shown? I tried to change the permission in init-containers as chmod 777 -R /u01/subpath but it throws an error saying cannot change the owner or permission of the folder.
try chown uid example:
name: testcontainer
command: ["sh", "-c", "chmod 777 /u01/ && chown 1000:1000 /u01/"]