gpt4 book ai didi

Kubernetes ReadWriteOnce Multi-Attach 在部署重新加载/重启时死锁

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

考虑下面的 PersistentVolumeClaim,以及使用它的 Deployment。

由于 ReadWriteOnce,PVC 一次只能被一个节点挂载。由于我的部署只有一个副本,我认为这应该没问题。但是,在重新启动/重新加载时,切换期间两个 Pod 将共存。

如果 Kubernetes 决定在与原始 Pod 相同的节点上启动后继 Pod,它们都将能够访问该卷并且切换正常。但是 - 如果它决定在它似乎更喜欢的新节点上启动它,我的部署最终会陷入僵局:

Multi-Attach error for volume "pvc-c474dfa2-9531-4168-8195-6d0a08f5df34" Volume is already used by pod(s) test-cache-5bb9b5d568-d9pmd



后继 pod 无法启动,因为卷挂载在另一个节点上,而原始 pod/节点当然不会放手,直到 pod 停止服务。在继任者上任之前不会是这样。

我在这里缺少什么?
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: vol-test
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: do-block-storage
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-cache
spec:
selector:
matchLabels:
app: test-cache-deployment
replicas: 1
template:
metadata:
labels:
app: test-cache-deployment
spec:
containers:
- name: test-cache
image: myrepo/test-cache:1.0-SNAPSHOT
volumeMounts:
- mountPath: "/test"
name: vol-mount
ports:
- containerPort: 8080
imagePullPolicy: Always
volumes:
- name: vol-mount
persistentVolumeClaim:
claimName: vol-name
imagePullSecrets:
- name: regcred

最佳答案

如果您使用 ReadWriteOnce,这是预期的行为.如果您查看手册,您会遇到以下信息:

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


Kubernetes 文档有 table显示哪些 PV 支持 ReadWriteMany (即同时在多个节点上进行写访问,例如 NFS)

如果你还坚持使用 ReadWriteOnce您可以使用 NodeAffinity并确保将 2 个副本安排到同一个节点,但这被认为是不好的做法,因为它错过了 Kubernetes 的全部意义。请注意,如果特定节点出现故障,您的所有副本都会出现故障。

您在评论中提到的理想状态可以通过 pod affinity 实现。 :

Pod affinity and pod anti-affinity allow you to specify rules about how pods should be placed relative to other pods. The rules are defined using custom labels on nodes and label selectors specified in pods. Pod affinity/anti-affinity allows a pod to specify an affinity (or anti-affinity) towards a group of pods it can be placed with. The node does not have control over the placement.



查询 this example来自 Kubernetes 文档关于 pods 亲和性。

关于Kubernetes ReadWriteOnce Multi-Attach 在部署重新加载/重启时死锁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62214105/

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