【问题标题】:How to change the persistent volume claims change default directory?如何更改持久卷声明更改默认目录?
【发布时间】:2021-07-13 10:33:06
【问题描述】:
 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```

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

【问题讨论】:

  • 您是否尝试过使用initContainer 来运行chmod,就像在这个答案中:stackoverflow.com/a/51195446/12257134 一样?
  • 我已经尝试过@DawidKruk,但是当它尝试运行 init-container 时用户也不是 root 用户,所以 chmod chown 一切都失败了
  • 我看到您的 securityContext 是在整个资源上定义的,并且可以按 containerinitContainer 分配它,如下所示:kubernetes.io/docs/tasks/configure-pod-container/…。请检查这是否适合您。

标签: kubernetes persistent-volumes persistent-volume-claims


【解决方案1】:

尝试 chown uid 示例:

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

【讨论】:

  • 我也尝试了 chown 但它仍然会引发错误,例如您没有权限 chmod 或 chown 该目录。
  • 使用 kubectl exec -it pod_name -- /bin/bash 部署并查看容器内部
猜你喜欢
  • 2021-11-22
  • 1970-01-01
  • 1970-01-01
  • 2014-05-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-27
  • 1970-01-01
相关资源
最近更新 更多