gpt4 book ai didi

kubernetes - 连接到 Kubernetes 中的持久卷?

转载 作者:行者123 更新时间:2023-12-02 11:35:47 25 4
gpt4 key购买 nike

我正在将堆栈转换为 k8s。数据库需要持久存储。

我已经使用了kubectl create -f pv.yaml

pv.yaml (根据@whites11 的回答进行了编辑):

kind: PersistentVolume
apiVersion: v1
metadata:
name: pv-volume
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/nfs"
claimRef:
kind: PersistentVolumeClaim
namespace: default
name: mongo-persisted-storage

然后我创建一个 example mongo replica set .

当我查看我的 k8s 仪表板时,我看到错误:

PersistentVolumeClaim is not bound: "mongo-persistent-storage-mongo-0" (repeated 2 times)

enter image description here

在持久卷选项卡中,我看到看起来不错的卷:

enter image description here

我无法确定下一步如何使卷声明成功发生。

编辑 #2

我进入了 GUI 上的 PVC 页面并手动向声明添加了一个卷(基于@whites11 的反馈)。我可以看到 PVC 已更新为卷,但仍处于待处理状态。

enter image description here

编辑 #3

意识到自从进行了@whites11 建议的更改后,pod 中的原始错误消息已更改。现在是“persistentvolume “pvvolume” not found(重复 2 次)”,我想我只需要弄清楚我在哪里写了 pvvolume,而不是 pv-volume。 (或者可能是 - 在某处被自动解析了?

enter image description here

最佳答案

您需要通过将适当的 claimRef 部分添加到 PV 规范来手动将您的 PV 绑定(bind)到您的 PVC。

在实践中,用你喜欢的方法编辑你的 PV,并添加一个类似于这样的部分:

claimRef:
name: mongo-persisted-storag
namespace: <your PVC namespace>

然后,您需要编辑 PVC 以绑定(bind)正确的卷,方法是在其 spec 部分添加以下内容:

volumeName: "<your volume name>"

这里解释了这个过程是如何工作的:https://docs.openshift.org/latest/dev_guide/persistent_volumes.html#persistent-volumes-volumes-and-claim-prebinding

关于kubernetes - 连接到 Kubernetes 中的持久卷?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50181488/

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