构建
2024年11月13日
一、认识
二、静态供应
2.1 编写 PV 配置文件
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-demo
spec:
storageClassName: test-pv
capacity:
storage: 2Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
nfs:
server: k8s-master
path: /mnt/nfs_share
2.2 创建 PV 存储资源
kubectl apply -f test-pv.yaml
2.3 编写 PVC 配置文件
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-demo
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 500Mi
2.4 创建 PVC 用户请求
kubectl apply -f test-pvc.yaml
2.5 验证 PVC PV 状态
kubectl get pv pv-demo
kubectl get pvc pvc-demo
三、动态供应
3.1 编写 StorageClass 配置
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: aws-ebs-sc
provisioner: kubernetes.io/aws-ebs
parameters:
type: gp2
fsType: ext4
reclaimPolicy: Retain
allowVolumeExpansion: true
volumeBindingMode: WaitForFirstConsumer
3.2 创建 StorageClass 应用
3.3 编写 PVC 配置文件
在创建 PVC
时,通过指定 storageClassName
绑定到特定的 StorageClass
:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: dynamic-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: aws-ebs-sc