gpt4 book ai didi

kubernetes - 如何将持久卷声明与 gcePersistentDisk 绑定(bind)?

转载 作者:行者123 更新时间:2023-12-04 16:50:44 25 4
gpt4 key购买 nike

我想将 PersistentVolumeClaim 与 gcePersistentDisk PersistentVolume 绑定(bind)。在我为得到它所做的步骤下面:

1. gcePersistentDisk 的创建:
gcloud compute disks create --size=2GB --zone=us-east1-b gce-nfs-disk
2. 定义 PersistentVolume 和 PersistentVolumeClaim

# pv-pvc.yml
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv
spec:
capacity:
storage: 2Gi
accessModes:
- ReadWriteOnce
gcePersistentDisk:
pdName: gce-nfs-disk
fsType: ext4
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nfs-pvc
labels:
app: test
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi

运行后 kubectl apply -f pv-pvc.yml , nfs-pvc未绑定(bind) nfs-pv .事实上,下面是我拥有的 PersistentVolume 和 PersistentVolumeClaim 的列表:
$ kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
nfs-pv 2Gi RWO Retain Available 30s
pvc-16e4cdf2-cd3d-11e7-83ae-42010a8e0243 2Gi RWO Delete Bound default/nfs-pvc standard 26s
$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
nfs-pvc Bound pvc-16e4cdf2-cd3d-11e7-83ae-42010a8e0243 2Gi RWO standard 59s

得到的 PersistentVolume 是我在 Google Container Engine 上创建的节点的磁盘上的一个卷。
那么,我错过了什么吗?

PS:kubernetes的版本
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.3", GitCommit:"f0efb3cb883751c5ffdbe6d515f3cb4fbe7b7acd", GitTreeState:"clean", BuildDate:"2017-11-08T18:39:33Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"7+", GitVersion:"v1.7.8-gke.0", GitCommit:"a7061d4b09b53ab4099e3b5ca3e80fb172e1b018", GitTreeState:"clean", BuildDate:"2017-10-10T18:48:45Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}

最佳答案

PersistentVolumeClaim , 你不需要创建 持久卷 对象或 gcePersistentDisk .相反,只创建一个 PVC,Kubernetes 会自动创建一个引用后备存储的 PV 对象。

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nfs-pvc
spec:
accessModes:
- ReadWriteOnce
storageClassName: ssd-sc # specify the storage class created below
resources:
requests:
storage: 10Gi

创建 存储类 所以它知道要使用哪个后备存储。如果删除 PVC 和存储类型( 类型:pd-ssd ),您可以指定它保留存储( reclaimPolicy: Retain )。
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: ssd-sc
provisioner: kubernetes.io/gce-pd
reclaimPolicy: Retain # Retain storage even if we delete PVC
parameters:
type: pd-ssd # ssd

关于kubernetes - 如何将持久卷声明与 gcePersistentDisk 绑定(bind)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47378592/

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