【问题标题】:Kubernetes: Can I mount different subPaths from the same PV onto different locations of the same container?Kubernetes:我可以将来自同一个 PV 的不同子路径挂载到同一个容器的不同位置吗?
【发布时间】:2019-01-24 20:46:08
【问题描述】:

我可以将来自同一个 PV 的不同子路径挂载到同一个容器的不同位置吗?

我在公司的 Kubernetes 集群上运行了几个 wordpress 实例。每个实例都有自己的持久化卷和容器。我设置的唯一特点是,我将 PV 的多个路径安装到容器的多个路径上。

自几周前我们将 Kubernetes 升级到当前版本以来,我所有的容器都运行良好。从那以后,地狱开始了。

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.11", GitCommit:"637c7e288581ee40ab4ca210618a89a555b6e7e9", GitTreeState:"clean", BuildDate:"2018-11-26T14:38:32Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.11", GitCommit:"637c7e288581ee40ab4ca210618a89a555b6e7e9", GitTreeState:"clean", BuildDate:"2018-11-26T14:25:46Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}

当重新启动一个 pod 时,如果它被安排在不同的节点上运行,它会卡在 PodInitializing 上并显示以下事件消息

卷“pvc-ac6b35f3-7716-11e8-adda-b60483de6a40”的多附加错误卷已独占附加到一个节点,无法附加到另一个节点

这是我的资源。


 一个 Ceph RBD 持久卷

它包含两个目录和一个文件

  • html/: php 文件目录
  • logs/: 有日志文件的目录
  • container-data.txt: 包含一些信息的文本文件

定义为:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: rbd-wordpress-mysite
  labels:
    app: wordpress
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi

我的豆荚

kind: Deployment
apiVersion: apps/v1beta1
metadata:
  name: wordpress-mysite
  labels:
    app: wordpress
  namespace: unibz
spec:
  template:
    metadata:
      name: wordpress-mysite
      labels:
        app: wordpress
      namespace: unibz
    spec:
      containers:
        - name: wordpress-mysite
          image: myimage
          volumeMounts:
          - mountPath: "/root/container-data.txt"
            name: wordpress-data
            subPath: container-data.txt
          - mountPath: "/var/www/html"
            name: wordpress-data
            subPath: html
          - mountPath: "/var/log/apache2"
            name: wordpress-data
            subPath: logs
          ports:
          - containerPort: 80
            name: wordpress-http
      volumes:
      - name: wordpress-data
        persistentVolumeClaim:
           claimName: rbd-wordpress-mysite
      - name: wordpress-conf
        configMap:
          name: wordpress-conf

这种使用持久性的方式是错误的吗?会不会是 Multi-Attach 错误的原因?

【问题讨论】:

    标签: kubernetes ceph persistent-volumes


    【解决方案1】:

    看起来您正试图将相同的PVC 附加到不同的node

    访问模式 在请求具有特定访问模式的存储时,声明使用与卷相同的约定

    在你的.yaml我可以看到,你已经设置了accessModes: ReadWriteOnce

    PersistentVolume 可以通过资源提供者支持的任何方式安装在主机上。如下表所示,提供者将具有不同的功能,并且每个 PV 的访问模式都设置为该特定卷支持的特定模式。例如,NFS 可以支持多个读/写客户端,但特定的 NFS PV 可能在服务器上导出为只读。每个 PV 都有自己的一组访问模式来描述特定 PV 的功能。

    访问方式有:

    • ReadWriteOnce – 卷可以由单个节点以读写方式挂载

    • ReadOnlyMany – 卷可以被许多节点以只读方式挂载

    • ReadWriteMany – 卷可以被许多节点以读写方式挂载

    从关于 Persistent Volumes 的 Kubernetes 文档中,您可以了解到 CephFS 确实支持所有 accessModes

    【讨论】:

    • 很遗憾,Ceph RBD 卷似乎不支持 ReadWriteMany
    • 似乎 RBD 一般不支持 ReadWriteMany,如table
    • @leonixyz 这是answer your question 吗?
    猜你喜欢
    • 2018-11-19
    • 1970-01-01
    • 2021-12-30
    • 1970-01-01
    • 2019-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-19
    相关资源
    最近更新 更多