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

标签 kubernetes ceph persistent-volumes

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

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

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

$ 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 并显示以下事件消息

Multi-Attach error for volume "pvc-ac6b35f3-7716-11e8-adda-b60483de6a40" Volume is already exclusively attached to one node and can't be attached to another

这是我的资源。


Ceph RBD PersistentVolume

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

  • 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 错误的原因?

最佳答案

看起来您正在尝试附加相同的 PVC进入不同的节点

Access Modes Claims use the same conventions as volumes when requesting storage with specific access modes

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

A PersistentVolume can be mounted on a host in any way supported by the resource provider. As shown in the table below, providers will have different capabilities and each PV’s access modes are set to the specific modes supported by that particular volume. For example, NFS can support multiple read/write clients, but a specific NFS PV might be exported on the server as read-only. Each PV gets its own set of access modes describing that specific PV’s capabilities.

The access modes are:

  • ReadWriteOnce – the volume can be mounted as read-write by a single node

  • ReadOnlyMany – the volume can be mounted read-only by many nodes

  • ReadWriteMany – the volume can be mounted as read-write by many nodes

来自关于 Persistent Volumes 的 Kubernetes 文档你可以读到 CephFS 确实支持所有 accessModes

关于Kubernetes:我可以将同一 PV 的不同子路径挂载到同一容器的不同位置吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54355060/

相关文章:

kubernetes - 自动重用包含数据的永久卷

kubernetes - 如何在kubernetes中注册新的API扩展?

amazon-web-services - Ingress 不更新 ALB

kubernetes - 带有Nginx入口的负载均衡Pod

kubernetes - 在 Kubernetes 错误中使用 RBD

centos - 强制 CEPH 同步和建议 CEPH 更新

ceph - 如何在循环设备上为 Ceph 创建 osd

persistent-volumes - kubeflow 管道定义中的 volume 和 pvolume 有什么区别?

spring-boot - 上游连接错误或在 header 之前断开连接/重置。重置原因:使用Spring Boot时连接终止

azure - 如何配置手动预配的 Azure 托管磁盘以用作 Kubernetes 持久卷?