PVC
清单文件
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
# PVC 名称
name: mypvc
namespace: default
spec:
# 要求支持访问模型
accessModes: ["ReadWriteMany"]
resources:
requests:
# 需要的数据容量
storage: 6Gi
---
apiVersion: v1
kind: Pod
metadata:
name: myapp-vol-pvc
namespace: default
spec:
containers:
- name: myapp
image: ikubernetes/myapp:v1
volumeMounts:
- name: html-vol
mountPath: /usr/share/nginx/html/
volumes:
- name: html-vol
persistentVolumeClaim:
# 使用指定的PVC
claimName: mypvc
查看pvc和pv状态
# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pv001 2Gi RWO,RWX Retain Available 25m
pv002 5Gi RWO Retain Available 26m
pv003 20Gi RWO,RWX Retain Bound default/mypvc 26m
pv004 10Gi RWO Retain Available 26m
pv005 10Gi RWO Retain Available 26m
# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
mypvc Bound pv003 20Gi RWO,RWX 6m
补充说明
- 如果pv处于Bound状态时,此时删除pv是会一直处在Terminating状态,知道pvc解除绑定,才会执行删除