gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 07:26:24 25 4
gpt4 key购买 nike

我可以将同一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com