k8s1.13版本
PV
apiVersion: v1
kind: PersistentVolume
metadata:
name: filesystem-pvc
spec:
capacity: #未来的属性可能包括 IOPS、吞吐量等
storage: 5Gi
volumeMode: Filesystem #volumeMode 的有效值可以是“Filesystem”或“Block”。如果未指定,volumeMode 将默认为“Filesystem”。这是一个可选的 API 参数
accessModes: #ReadWriteOnce——该卷可以被单个节点以读/写模式挂载,ReadOnlyMany——该卷可以被多个节点以只读模式挂载,ReadWriteMany——该卷可以被多个节点以读/写模式挂载
- ReadWriteOnce #一个卷一次只能使用一种访问模式挂载,即使它支持很多访问模式
persistentVolumeReclaimPolicy: Recycle
storageClassName: slow #可选,一个特定类别的 PV 只能绑定到请求该类别的 PVC。没有 storageClassName
的 PV 就没有类,它只能绑定到不需要特定类的 PVC。
mountOptions:
- hard
- nfsvers=4.1
nfs:
path: /tmp
server: 172.17.0.2
--volumeMode为Block,目前只有如下PV支持
AWSElasticBlockStore
AzureDisk
FC (Fibre Channel)
GCEPersistentDisk
iSCSI
Local volume
RBD (Ceph Block Device)
VsphereVolume (alpha)
--回收策略persistentVolumeReclaimPolicy
Retain(保留)——手动回收 Recycle(回收)——基本擦除(rm -rf /thevolume/*) Delete(删除)——关联的存储资产(例如 AWS EBS、GCE PD、Azure Disk 和 OpenStack Cinder 卷)将被删除 当前,只有 NFS 和 HostPath 支持回收策略。AWS EBS、GCE PD、Azure Disk 和 Cinder 卷支持删除策略。
卷可以处于以下的某种状态:
Available(可用)——一块空闲资源还没有被任何声明绑定
Bound(已绑定)——卷已经被声明绑定
Released(已释放)——声明被删除,但是资源还未被集群重新声明
Failed(失败)——该卷的自动回收失败
PVC
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: filesystem-pvc #pvc和pv通过名字进行匹配 spec: accessModes: #与pv一样,注意:这里pv和pvc一样才会匹配上 - ReadWriteOnce volumeMode: Filesystem #与pv一样 resources: #与pv一样 requests: storage: 8Gi storageClassName: slow selector: matchLabels: release: "stable" matchExpressions: - {key: environment, operator: In, values: [dev]}
--selector
matchLabels:volume 必须有具有该值的标签
matchExpressions:这是一个要求列表,通过指定关键字,值列表以及与关键字和值相关的运算符组成。有效的运算符包括 In、NotIn、Exists 和 DoesNotExist。
所有来自 matchLabels 和 matchExpressions 的要求都被“与”在一起——它们必须全部满足才能匹配。
--storageClassName
PVC不一定要请求类。其storageClassName 设置为 "" 的PVC始终被解释为没有请求类的PV
与 PVC 具有相同 storageClassName 的 PV 才能绑定到 PVC
pod使用声明
apiVersion: v1 kind: Pod metadata: name: pod-with-filesystem-volume spec: containers: - name: fc-container image: fedora:26 command: ["/bin/sh", "-c"] args: [ "tail -f /dev/null" ] volumeDevices: - name: data devicePath: /dev/xvda volumes: - name: data persistentVolumeClaim: claimName: filesystem-pvc
或者直接在staefulset中定义pvc
apiVersion: apps/v1beta1 kind: StatefulSet metadata: name: web spec: serviceName: "nginx" replicas: 3 volumeClaimTemplates: - metadata: name: test spec: accessModes: [ "ReadWriteOnce" ] resources: requests: storage: 5Gi template: metadata: labels: app: nginx spec: containers: - name: magine1989 image: nginx:1.11.10 volumeMounts: - mountPath: "/mnt/rbd" name: test
Storeclass
StorageClass
为管理员提供了描述存储 "class(类)" 的方法。 不同的 class 可能会映射到不同的服务质量等级或备份策略,或由群集管理员确定的任意策略。 Kubernetes 本身不清楚各种 class 代表的什么。这个概念在其他存储系统中有时被称为“配置文件”。
kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: name: standard provisioner: kubernetes.io/aws-ebs parameters: type: gp2 reclaimPolicy: Retain mountOptions: - debug
具体参考:https://kubernetes.io/docs/concepts/storage/storage-classes/