24 PersistentVolume 数据持久化
PersistentVolume 属于集群的系统资源,是和 Node 平级的一种对象,Pod 对它没有管理权,只有使用权。
StorageClass 它抽象了特定类型的存储系统(比如 Ceph、NFS),在 PVC 和 PV 之间充当“协调人”的角色,帮助 PVC 找到合适的 PV。
apiVersion: v1 kind: PersistentVolume metadata: name: host-10m-pv spec: storageClassName: host-vol accessModes: - ReadWriteOnce capacity: storage: 10Mi hostPath: path: /tmp/host-10m-pv/
---
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: host-5m-pvc spec: storageClassName: host-vol accessModes: - ReadWriteOnce resources: requests: storage: 5Mi
|
mkdir /tmp/host-10m-pv kubectl apply -f host-path-pv-pvc.yml kubectl get pv
kubectl get pvc
|
apiVersion: v1 kind: Pod metadata: name: host-pvc-pod spec: volumes: - name: host-pvc-vol persistentVolumeClaim: claimName: host-5m-pvc containers: - name: ngx-pvc-pod image: nginx:alpine ports: - containerPort: 80 volumeMounts: - name: host-pvc-vol mountPath: /tmp
|
kubectl apply -f host-pvc-pod.yml kubectl get pod -o wide kubectl exec -it host-pvc-pod -- sh cd /tmp && touch a.md
/tmp/host-10m-pv/
|
25 NFS 网络共享存储
…
References