如何更改持久卷声明更改默认目录?

问题描述

 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','ls -lrt /u01 ']
      volumes:
      - name: testvol
        persistentVolumeClaim:
          claimName: testpvc```

我正在尝试创建具有上述规范的工作。文件夹 1 和文件夹 2 的用户以 root 身份出现。当持久卷声明安装到具有如图所示的子路径的文件夹时,如何更改文件夹的用户?我尝试将 init-containers 中的权限更改为 chmod 777 -R /u01/subpath 但它抛出一个错误提示无法更改文件夹的所有者或权限。

解决方法

尝试 chown uid 示例:

name: testcontainer
command: ["sh","-c","chmod 777 /u01/ && chown 1000:1000 /u01/"]