Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在IBM Cloud Kubernetes中创建挂载PVC时出现只读错误_Kubernetes_Ibm Cloud_Nexus3_Ibm Cloud Kubernetes_Iks - Fatal编程技术网

在IBM Cloud Kubernetes中创建挂载PVC时出现只读错误

在IBM Cloud Kubernetes中创建挂载PVC时出现只读错误,kubernetes,ibm-cloud,nexus3,ibm-cloud-kubernetes,iks,Kubernetes,Ibm Cloud,Nexus3,Ibm Cloud Kubernetes,Iks,我正在尝试将Nexus3部署为IBM云服务中的Kubernetes吊舱。我得到这个错误,可能是因为PVC是为该用户以只读方式安装的。例如,我在博士后的其他时候也遇到过这个问题,但我记不起如何解决它: mkdir: cannot create directory '../sonatype-work/nexus3/log': Permission denied mkdir: cannot create directory '../sonatype-work/nexus3/tmp': Permissi

我正在尝试将Nexus3部署为IBM云服务中的Kubernetes吊舱。我得到这个错误,可能是因为PVC是为该用户以只读方式安装的。例如,我在博士后的其他时候也遇到过这个问题,但我记不起如何解决它:

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

nexus3 Dockerfile的结构使其作为非root用户运行。但是,NFS文件存储需要root用户访问和写入。有几种方法可以解决这个问题。首先,您可以重新构造Dockerfile,将非root用户临时添加到root,并更改卷装载权限。以下是相关说明:

另一个选项是运行initContainer(),在主容器运行之前更改装载路径所有权。initContainer的外观如下所示:

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

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

安装并更新资源以使用新的可用存储类。用法示例:

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

谢谢你的回答。快速提问。。。例如,当我使用相同的PVC卷部署Postgres时,为什么我没有这个问题?Postgres不会将文件写入根目录…不同之处在于Dockerfile/entrypoint脚本的结构。对于postgres,容器以root权限运行,
/docker entrypoint.sh
作为非root用户进程启动
postgres
。因此,在本例中,入口点脚本以
root
user的身份运行。入口点可以执行
chown-R postgres“$PGDATA”
,因为它具有root权限。对于Nexus,由于
用户Nexus
,容器以非根用户身份运行。NFS卷由主机上的root用户拥有,但Dockerfile正试图使装载路径由非root用户拥有。