在 GKE 中,我们可以通过 PVC 对象创建持久卷时指定区域或区域吗?
In GKE, can we specify the zone or region of a persistent volume when we create it through a PVC object
我希望我的持久卷驻留在一个特定的区域,比如 us-central1-a,但我想通过 PVC 部署它,而不是直接创建 PV 的对象。这在 GKE 中可行吗?
你应该使用Regional persistent disks
To enable dynamic provisioning of regional persistent disks, create a StorageClass with the replication-type parameter, and specify zone constraints in allowedTopologies.
For example, the following manifest describes a StorageClass named regionalpd-storageclass that uses standard persistent disks and that replicates data to the europe-west1-b and europe-west1-c zones:
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: regionalpd-storageclass
provisioner: kubernetes.io/gce-pd
parameters:
type: pd-standard
replication-type: regional-pd
volumeBindingMode: WaitForFirstConsumer
allowedTopologies:
- matchLabelExpressions:
- key: topology.kubernetes.io/zone
values:
- europe-west1-b
- europe-west1-c
Create a PersistentVolumeClaim object, and use the storageClassName field to refer to the StorageClass you created. For example, the following manifest creates a PersistentVolumeClaim named regional-pvc and references the regionalpd-storageclass
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: regional-pvc
namespace: testns
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 200Gi
storageClassName: regionalpd-storageclass
The following manifest is an example Pod using the previously created PersistentVolumeClaim:
kind: Pod
apiVersion: v1
metadata:
name: task-pv-pod
spec:
volumes:
- name: task-pv-storage
persistentVolumeClaim:
claimName: regional-pvc
containers:
- name: task-pv-container
image: nginx
ports:
- containerPort: 80
name: "http-server"
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: task-pv-storage
您可以按照这个 guide 来操作,它会向您展示如何做到这一点
似乎无法为 PV 或 PVC 指定区域,但可以在 StorageClass 上设置 volumeBindingMode: WaitForFirstConsumer
以确保 PV 与使用它的 pod 位于同一区域.然后可以使用 pod 上的 nodeSelector 选择区域。
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: ssd
parameters:
type: pd-ssd
provisioner: kubernetes.io/gce-pd
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true
聚氯乙烯:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: db
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 200Gi
storageClassName: ssd
连播:
kind: Pod
apiVersion: v1
metadata:
name: foo
spec:
nodeSelector:
failure-domain.beta.kubernetes.io/zone: us-central1-a
containers:
...
我希望我的持久卷驻留在一个特定的区域,比如 us-central1-a,但我想通过 PVC 部署它,而不是直接创建 PV 的对象。这在 GKE 中可行吗?
你应该使用Regional persistent disks
To enable dynamic provisioning of regional persistent disks, create a StorageClass with the replication-type parameter, and specify zone constraints in allowedTopologies.
For example, the following manifest describes a StorageClass named regionalpd-storageclass that uses standard persistent disks and that replicates data to the europe-west1-b and europe-west1-c zones:
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: regionalpd-storageclass
provisioner: kubernetes.io/gce-pd
parameters:
type: pd-standard
replication-type: regional-pd
volumeBindingMode: WaitForFirstConsumer
allowedTopologies:
- matchLabelExpressions:
- key: topology.kubernetes.io/zone
values:
- europe-west1-b
- europe-west1-c
Create a PersistentVolumeClaim object, and use the storageClassName field to refer to the StorageClass you created. For example, the following manifest creates a PersistentVolumeClaim named regional-pvc and references the regionalpd-storageclass
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: regional-pvc
namespace: testns
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 200Gi
storageClassName: regionalpd-storageclass
The following manifest is an example Pod using the previously created PersistentVolumeClaim:
kind: Pod
apiVersion: v1
metadata:
name: task-pv-pod
spec:
volumes:
- name: task-pv-storage
persistentVolumeClaim:
claimName: regional-pvc
containers:
- name: task-pv-container
image: nginx
ports:
- containerPort: 80
name: "http-server"
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: task-pv-storage
您可以按照这个 guide 来操作,它会向您展示如何做到这一点
似乎无法为 PV 或 PVC 指定区域,但可以在 StorageClass 上设置 volumeBindingMode: WaitForFirstConsumer
以确保 PV 与使用它的 pod 位于同一区域.然后可以使用 pod 上的 nodeSelector 选择区域。
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: ssd
parameters:
type: pd-ssd
provisioner: kubernetes.io/gce-pd
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true
聚氯乙烯:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: db
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 200Gi
storageClassName: ssd
连播:
kind: Pod
apiVersion: v1
metadata:
name: foo
spec:
nodeSelector:
failure-domain.beta.kubernetes.io/zone: us-central1-a
containers:
...