[TOC] # 介绍 * PV和PVC使得K8s具备存储的逻辑抽象能力 * PV和Node是资源的提供者,由K8s集群管理员设置 * PVC和Pod是资源的使用者,由K8s集群的使用者(开发人员)配置 ``` # 定义PV apiVersion: v1 kind: PersistentVolume metadata: name: nginx-pv spec: accessModes: - ReadWriteMany capacity: storage: 2Gi nfs: path: /nfs/data/nginx # 在nfs server 该路径需要存在 server: 192.168.136.200 --- # 定义PVC,用于消费PV apiVersion: v1 kind: PersistentVolumeClaim metadata: name: nginx-pvc spec: accessModes: - ReadWriteMany resources: requests: storage: 2Gi --- # 定义Pod,指定需要使用的PVC apiVersion: apps/v1beta1 kind: Deployment metadata: name: nginx spec: selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - image: nginx name: mysql ports: - containerPort: 80 volumeMounts: - name: nginx-persistent-storage mountPath: /usr/share/nginx/html volumes: - name: nginx-persistent-storage persistentVolumeClaim: claimName: nginx-pvc ``` >PVC与PV通过 `PersistentVolume`中的`spec.accessModes`和`spec.capacity..storage`与`PersistentVolumeClaim`中的`spec.accessModes`和`spec.resources.requests.storage`值一致来匹配。