使用持久化存储
当运行在一个pod中的应用程序需要将数据保持到磁盘上,并且即使该pod重新调度到另一个节点时也要求具有相同的数据可用。由于这些数据需要可以从任何集群节点访问,因此必须将其存储到某种类型的网络存储(NAS)中。
1.使用GCE持久磁盘作为pod存储卷
1.1 创建GCE持久磁盘
这需要和集群创建在一个region里。例如名子是:my-data-dis
1.2创建一个使用GCE持久磁盘卷的pod
yaml
--------------------
apiVersion: v1
kind: Pod
metadata:
name: test-pd
spec:
containers:
- image: k8s.gcr.io/test-webserver
name: test-container
volumeMounts:
- mountPath: /test-pd
name: test-volume
volumes:
- name: test-volume
# This GCE PD must already exist.
gcePersistentDisk:
pdName: my-data-disk
fsType: ext4
--------------------
gcePersistentDisk:卷类型时GCE持久磁盘
pdName:持久磁盘的名称必须与先前创建的实际PD一致
fsType: