-
Notifications
You must be signed in to change notification settings - Fork 104
/
pod_use_pvc.yaml
55 lines (52 loc) · 1.55 KB
/
pod_use_pvc.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
apiVersion: v1
kind: Namespace
metadata:
name: dev
---
# 按顺序定义 pv,pvc,pod
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-hostpath
namespace: dev # pv允许被跨namespace使用
spec:
capacity:
storage: 1Ti # 此卷容量,单位支持 Ti T Gi G Mi M Ki K,可以改小,但强烈不建议
accessModes:
- ReadWriteMany # 允许多个客户端读写,还有ReadWriteOnce(允许单个节点读写),ReadOnlyMany(允许多个节点只读),单个节点可以包含多个Pod
persistentVolumeReclaimPolicy: Retain # 删除pvc时,pv的回收策略,这里为保留。还有 Delete(删除)
storageClassName: node-local # 存储分类定义,会被pvc引用
hostPath: # 可换为 nfs 等其他存储
path: /home/host-pv-dir
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-hostpath
spec:
accessModes:
- ReadWriteMany # 必须和PV一致才能匹配
storageClassName: node-local # 存储分类定义,对应pv定义
resources:
requests:
storage: 500Mi # pvc一旦创建,若要修改申请的空间大小,只能增加不能减少!
---
apiVersion: v1
kind: Pod
metadata:
name: busybox-use-pvc
labels:
app: busybox
spec:
containers:
- name: write
image: busybox
command: [ "sh", "-c" ]
args: [ "echo 'hellok8s, pvc used!' > /write_dir/data; sleep infinity" ]
volumeMounts:
- mountPath: /write_dir
name: pvc-dir
volumes:
- name: pvc-dir
persistentVolumeClaim:
claimName: pvc-hostpath # 对应pvc名称