【问题标题】:Read only error when creating a mounting a PVC in IBM Cloud Kubernetes在 IBM Cloud Kubernetes 中创建挂载 PVC 时出现只读错误
【发布时间】:2018-03-01 04:29:55
【问题描述】:

我正在尝试将 Nexus3 部署为 IBM Cloud 服务中的 Kubernetes pod。我收到此错误,可能是因为 PVC 安装为该用户的只读。例如,我在 Postgres 的其他时候也遇到过这个问题,但我不记得如何解决它:

mkdir: cannot create directory '../sonatype-work/nexus3/log': Permission denied
mkdir: cannot create directory '../sonatype-work/nexus3/tmp': Permission denied
Java HotSpot(TM) 64-Bit Server VM warning: Cannot open file ../sonatype-work/nexus3/log/jvm.log due to No such file or directory

Warning:  Cannot open log file: ../sonatype-work/nexus3/log/jvm.log
Warning:  Forcing option -XX:LogFile=/tmp/jvm.log
Unable to update instance pid: Unable to create directory /nexus-data/instances
/nexus-data/log/karaf.log (No such file or directory)
Unable to update instance pid: Unable to create directory /nexus-data/instances

这些是 PVC 和 POD yaml:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nexus-pvc
  annotations:
    volume.beta.kubernetes.io/storage-class: "ibmc-file-retain-bronze"
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi

apiVersion: v1
kind: Pod
metadata:
  name: nexus
  labels:
    name: nexus
spec:
  containers:
    - name: nexus
      image: sonatype/nexus3
      ports:
        - containerPort: 8081
      volumeMounts:
        - name: nexus-data
          mountPath: /nexus-data
        - name: tz-config
          mountPath: /etc/localtime
  volumes:
  - name: nexus-data
    persistentVolumeClaim:
      claimName: nexus-pvc
  - name: tz-config
    hostPath:
      path: /usr/share/zoneinfo/Europe/Madrid

【问题讨论】:

    标签: kubernetes ibm-cloud nexus3 ibm-cloud-kubernetes iks


    【解决方案1】:

    nexus3 Dockerfile 的结构使其以非 root 用户身份运行。但是,NFS 文件存储需要 root 用户才能访问和写入。有几种方法可以解决这个问题。一,你可以重构你的 Dockerfile 来临时将非 root 用户添加到 root 并更改卷挂载权限。以下是相关说明:https://console.bluemix.net/docs/containers/cs_storage.html#nonroot

    另一个选项是运行一个 initContainer (https://kubernetes.io/docs/concepts/workloads/pods/init-containers/),它会在主容器运行之前更改挂载路径的所有权。 initContainer 看起来像这样:

    initContainers:
          - name: permissionsfix
            image: ubuntu:latest
            command: ["/bin/sh", "-c"]
            args:
              - >
                chown 1000:1000 /mount;
            volumeMounts:
            - name: volume
              mountPath: /mount
    

    【讨论】:

    • 感谢您的回答。快速提问......为什么我没有这个问题,例如当我使用相同的 PVC 卷部署 Postgres 时? Postgres 不会以 root 身份写入文件...
    • 不同之处在于 Dockerfile / 入口点脚本的结构。使用 postgres,容器以 root 权限运行,/docker-entrypoint.sh 以非 root 用户进程启动 postgres。所以在这种情况下,入口点脚本以root 用户身份运行。入口点可以执行chown -R postgres "$PGDATA",因为它具有root 权限。对于 Nexus,由于USER nexus,容器以非 root 身份运行。 NFS 卷由主机上的 root 拥有,但 Dockerfile 试图让挂载路径归非 root 用户所有。
    【解决方案2】:

    文件存储存在这些权限问题。不要使用基于文件的卷,而是使用基于块的卷。

    安装block storage plugin 并更新您的资源以使用新可用的存储类。使用示例:

    storage:
      type: persistent-claim
      size: 100Gi
      deleteClaim: false
      class: "ibmc-block-retain-bronze"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-09
      • 2020-05-04
      • 2019-10-08
      • 1970-01-01
      • 1970-01-01
      • 2020-10-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多