gpt4 book ai didi

kubernetes - 谷歌云平台 (GCP) : mounting multiple volumes kubernetes

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

我正在通过 Google 云平台 (GCP) kubernetes 引擎设置一个容器。我需要安装多个卷,因为容器是以这种方式创建的。这些卷必须是持久的,因此我采用了 NFS 方法。我有一个运行 NFS 服务的虚拟机,它导出了几个目录。

我在下面给出了 yaml 示例文件。

deployment.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: myapp-branch
labels:
component: myapp-branch
spec:
template:
metadata:
labels:
component: myapp-branch
spec:
imagePullSecrets:
- name: myprivatekey
containers:
- name: myapp-branch
image: mydockerrepo/myapp/webapp:6.6
command: ["/bin/sh", "-ec", "while :; do echo '.'; sleep 100 ; done"]
env:
- name: myapp_UID
value: "1011"
- name: myapp_GID
value: "1011"
- name: myapp_USER
value: "myapp_branch"
- name: myapp_XMS_G
value: "1"
- name: myapp_XMX_G
value: "6"
volumeMounts:
- mountPath: /mypath1/path1
name: pvstorestorage
- mountPath: /mypath2/path2
name: mykeys
volumes:
- name: pvstorestorage
persistentVolumeClaim:
claimName: standalone
- name: mykeys
persistentVolumeClaim:
claimName: conf

PVAndPVC.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
name: standalone
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
nfs:
server: 10.2.1.6
path: "/exports/path1"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: standalone
spec:
accessModes:
- ReadWriteMany
storageClassName: ""
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: conf
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
nfs:
server: 10.2.1.6
path: "/exports/path2"

---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: conf
spec:
accessModes:
- ReadWriteMany
storageClassName: ""
resources:
requests:
storage: 1Gi

应用它们后,我看到容器(/mypath1/path1 和/mypath2/path2)的两个卷挂载都挂载到 nfs 的相同挂载点(/exports/path2,第二个)。这发生在 persistentVolumeClaim 上,我尝试了 EmptyDir,它工作正常。如果有人尝试过这种方法并知道解决方案,那将非常有帮助。

最佳答案

您必须在您的 PVC (PersistentVolumeClaim) 定义中添加规则,使它们匹配各自正确的 PV (PersistentVolume)。

有相同的名字是不够的。

将您的 PV 和 PVC 定义更改为类似(未测试)的内容:

apiVersion: v1
kind: PersistentVolume
metadata:
name: standalone
labels:
type: standalone
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
nfs:
server: 10.2.1.6
path: "/exports/path1"
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: conf
labels:
type: conf
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
nfs:
server: 10.2.1.6
path: "/exports/path2"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: standalone
spec:
accessModes:
- ReadWriteMany
storageClassName: ""
resources:
requests:
storage: 1Gi
selector:
matchLabels:
type: standalone
---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: conf
spec:
accessModes:
- ReadWriteMany
storageClassName: ""
resources:
requests:
storage: 1Gi
selector:
matchLabels:
type: conf

(通常,我在 PV 中添加了一个 metadata.labels.type,在 PVC 中添加了一个 spec.selector.matchLabels)

此外,使用 kubectl get pvkubectl get pvc 查看它是如何工作的并简化调试

关于kubernetes - 谷歌云平台 (GCP) : mounting multiple volumes kubernetes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58023153/

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