1、什么是 pv 和pvc html
一、 PersistentVolume(PV)是集群中已由管理员配置的一段网络存储。 集群中的资源就像一个节点是一个集群资源。 PV是诸如卷之类的卷插件,可是具备独立于使用PV的任何单个pod的生命周期。 该API对象捕获存储的实现细节,即NFS,iSCSI或云提供商特定的存储系统。python
PV 支持的类型nginx
经常使用的 类型有api
GCEPersistentDisk 服务器
AWSElasticBlockStore 网络
AzureFile app
AzureDisk ide
FC (Fibre Channel) spa
FlexVolume 插件
Flocker
NFS
iSCSI
RBD (Ceph Block Device)
CephFS
Cinder (OpenStack block storage)
Glusterfs
VsphereVolume
Quobyte Volumes
HostPath
VMware Photon
Portworx Volumes
ScaleIO Volumes
二、pv
的访问模式
ReadWriteOnce:单个节点读写
ReadOnlyMany:多节点只读
ReadWriteMany:多节点读写。挂载时只能使用一种模式。
三、pv
的回收模式
Retain – 须要管理员手工回收。
Recycle – 清除 PV 中的数据,效果至关于执行 rm -rf /thevolume/*。
Delete – 删除
建立 pv , 已nfs 存储为例
一、安装 nfs 服务器
二、建立存储路径
三、访问目录受权
mkdir -p /data/test/v1
echo "/data/test/v1 *(rw,sync,no_root_squash)" >> /etc/exports
exportfs -avr
编写yaml 文件
apiVersion: v1 kind: PersistentVolume metadata: name: test01-pv spec: capacity: storage: 1Gi accessModes: - ReadWriteMany storageClassName: test01-pv persistentVolumeReclaimPolicy: Recycle nfs: path: /data/test/v1 server: 192.168.222.247
kubectl create -f test01_pv.yaml
pvc 的绑定
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: test01-pvc namespace: test01 spec: storageClassName: test01-pv accessModes: - ReadWriteMany resources: requests: storage: 1Gi --- apiVersion: v1 kind: Pod metadata: name: myapp namespace: test01 spec: containers: - name: myapp image: ikubernetes/myapp:v1 volumeMounts: - name: html mountPath: /usr/share/nginx/html volumes: - name: html persistentVolumeClaim: claimName: test01-pvc
kubectl create -f test01_pod_pvc.yaml
查看 pvc 和pod
绑定状态的pv 没法直接删除