1

我正在尝试将 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
4

2 回答 2

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
于 2018-03-01T14:14:45.833 回答
0

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

安装块存储插件并更新您的资源以使用新可用的存储类。使用示例:

storage:
  type: persistent-claim
  size: 100Gi
  deleteClaim: false
  class: "ibmc-block-retain-bronze"
于 2021-03-19T09:08:20.730 回答