PV 分类
- 静态PV:
由管理员创建, 定义了后端真实存储信息.
- 动态PV:
会通过关联的 StorageClass (sc) ,动态的申请后端存储资源.
使用动态PV的 PVC 必需指定 sc的名称.
当用户的pvc 没有可绑定的pv时, 集群会自动创建 pvc.
换句话说, sc 的出现, 就是为了解决高效使用存储资源.
使用例:
在StatefulSet中使用pvc 模板的方式去部署, 可以省掉手动创建pvc过程.
前提是, 已经创建好 sc.
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: postgres
labels:
app: postgres
spec:
replicas: 1
template:
metadata:
name: postgres
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:9.6
imagePullPolicy: IfNotPresent
env:
- name: POSTGRES_USER
value: kong
- name: POSTGRES_DB
value: kong
- name: POSTGRES_PASSWORD
value: kong
- name: PGDATA
value: /var/lib/postgresql/postgresql/data
- name: POSTGRES_INITDB_WALDIR
value: /var/lib/postgresql/postgresql/dblogs/logs
volumeMounts:
- name: postgresql-pvc
mountPath: /var/lib/postgresql
resources:
requests:
cpu: 50m
memory: 100Mi
limits:
cpu: 50m
memory: 100Mi
selector:
matchLabels:
app: postgres
serviceName: postgres
volumeClaimTemplates:
- metadata:
name: postgresql-pvc
spec:
accessModes:
- ReadWriteOnce
storageClassName: gp2
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: Service
metadata:
name: postgres
spec:
selector:
app: postgres
ports:
- port: 5432
targetPort: 5432
type: ClusterIP
网友评论