Kubernetes-PV/PVC

PV (Persistent Volume)

和Volume的区别

  • 只能是网络存储
  • 独立于Pod之外

PV支持的主流存储方案:

  • GCEPersistentDisk
  • AWSElasticBlockStore
  • AzureFile
  • AzureDisk
  • FC (Fibre Channel)
  • Flocker
  • NFS
  • iSCSI
  • RBD (Ceph Block Device)
  • CephFS
  • Cinder (OpenStack block storage)
  • Glusterfs
  • VsphereVolume
  • Quobyte Volumes
  • HostPath (single node testing only – local storage is not supported in any way and WILL NOT WORK in a multi-node cluster)
  • VMware Photon

创建PV

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv001
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Recycle 
  nfs:
    path: /data/k8s/
    server: 172.16.1.131

accessModes

  • ReadWriteOnce – PV以 read-write 挂载到一个节点
  • ReadOnlyMany – PV以read-only方式挂载到多个节点
  • ReadWriteMany – PV以read-write方式挂载到多个节点

Reclaim

当前支持的回收策略:

  • Retain – 允许用户手动回收
  • Recycle – 删除PV上的数据 (“rm -rf /thevolume/*”)
  • Delete – 删除PV

Phase

  • Available – PV可以被使用
  • Bound – PV被绑定到PVC
  • Released – 被绑定的PVC被删除,可以被Reclaim
  • Failed – 自动回收失败

PVC (Persistent Volume Claim)

创建PVC

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: myclaim
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 8Gi

Phase

Pending – 等待可用的PV
Bound – PV被绑定到PVC
Lost – 找不到绑定的PV

在Pod中使用

kind: Pod
apiVersion: v1
metadata:
name: mypod
spec:
containers:
- name: myfrontend
  image: dockerfile/nginx
  volumeMounts:
  - mountPath: "/var/www/html"
    name: mypd
volumes:
- name: mypd
  persistentVolumeClaim:
    claimName: myclaim

猜你喜欢

转载自www.cnblogs.com/wangyiyang/p/12194759.html