k8s 的St o r a g e C l a s s 存储 类 和 pv 、 pvc 、 p r o v i s i o n e r 、 物理 存储 的链路
StorageClass能自动创建pv
在控制器中,直接声明storageClassName,不仅能自动创建pvc,也能自动创建pv
stoageclass来自于provisioner,provisioner来自于pod,pod来自于镜像。也就是provisioner的镜像。镜像里面有提供provisioner相关的代码。




StorageClass是一种kind,也就是一种k8s的API资源,是一个动态存储卷。
先看pv、pvc:







kubectl get sc # storageclass
kubectl get sa # serviceaccount


# StorageClass (iscsi-scsi-storage.yaml)
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: iscsi-scsi-storage
provisioner: example.com/iscsi
parameters:
targetPortal: "192.168.1.100:3260"
lun: "0"
fsType: "ext4"
chapAuthEnabled: "true"
# StatefulSet (postgres-statefulset.yaml)
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: postgres-cluster
spec:
replicas: 3
selector:
matchLabels:
app: postgres
template:
spec:
containers:
- name: postgres
image: postgres:14
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
volumeClaimTemplates:
- metadata:
name: postgres-data
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: iscsi-scsi-storage
resources:
requests:
storage: 1Ti





