gpt4 book ai didi

Kubernetes 卷 hostPath 不适用于多个副本

转载 作者:行者123 更新时间:2023-12-02 11:48:32 26 4
gpt4 key购买 nike

我想将卷用于同时具有多个副本的部署。

我正在使用 hostPath现在的卷类型是 hostPath仅适用于一个 pod,其他 pod 无法同时访问卷。

如何同时使用卷的所有副本?

部署文件:

apiVersion: apps/v1
kind: Deployment
metadata:
name: pps-wordpress
labels:
app: wordpress
spec:
replicas: 4
selector:
matchLabels:
app: wordpress
template:
metadata:
labels:
app: wordpress
spec:
containers:
- name: wordpress
image: meysam001/wordpress
volumeMounts:
- name: aws-storage
mountPath: /var/www/html
ports:
- containerPort: 80
volumes:
- name: aws-storage
hostPath:
path: /mnt/s3

最佳答案

对于您的问题,我建议使用 Kubernetes 中的存储解决方案基础。它叫做PersistentVolumeClaim .此资源独立于 Pods 存在.数据在 Pod 的整个生命周期中,此卷上的数据仍然存在。它可以比作NFS 自动安装在操作系统的引导上。

您可能会发现这些多种安装选项对于满足所有需求很有用您的 Pod 生态系统:

ReadWriteOnce - 单节点读写模式的卷

ReadOnlyMany - 许多节点处于只读模式的卷

ReadWriteMany - 所有消费者的读写模式

要在 ReadWriteMany 模式下创建 30Gi 卷,请像这样部署 yaml:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: helloweb-disk
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 30Gi

请注意,此功能适用于云供应商,显然不适用于私有(private)云供应商云。

关于Kubernetes 卷 hostPath 不适用于多个副本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51708993/

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