CSI
(Container Storage Interface),旨在能为容器编排引擎和存储系统间建立一套标准的存储调用接口,通过该接口能为容器编排引擎提供存储服务。较过去FlexVolume
的方案明显会更好一些,虽然官方会继续支持,但明显CSI
才是未来。
目前阿里云ACK的CSI插件还处于公测阶段,今天来测试一下。
CSI相关组件
Plugin 插件:
1
2
3
4
5
6
7
8
|
➜ ~ kubectl get pods -l app=csi-plugin
NAME READY STATUS RESTARTS AGE
csi-plugin-2kn6r 6/6 Running 0 4d20h
csi-plugin-7jb9x 6/6 Running 0 4d20h
csi-plugin-btxs7 6/6 Running 0 4d20h
csi-plugin-fnlx6 6/6 Running 0 4d20h
csi-plugin-nh7dx 6/6 Running 0 4d20h
csi-plugin-scs6p 6/6 Running 0 4d20h
|
Provisioner
:负责创建EBS
1
2
3
|
➜ ~ kubectl get pods -l app=csi-provisioner
NAME READY STATUS RESTARTS AGE
csi-provisioner-0 4/4 Running 0 4d20h
|
api-resources
1
2
3
|
➜ ~ kubectl api-resources|grep csi
csidrivers storage.k8s.io false CSIDriver
csinodes storage.k8s.io false CSINode
|
StorageClasses
默认提供5个StorageClass
,分别对应不同类型的云盘。
sc |
云盘类型 |
alicloud-disk-available |
会通过efficiency、ssd、common的顺序依次尝试创建云盘 |
alicloud-disk-efficiency |
创建essd类型云盘 |
alicloud-disk-essd |
创建普通云盘 |
alicloud-disk-essd |
创建ssd类型云盘 |
alicloud-disk-topology |
创建高效云盘 |
1
2
3
4
5
6
7
|
➜ ~ kubectl get sc
NAME PROVISIONER AGE
alicloud-disk-available diskplugin.csi.alibabacloud.com 4d20h
alicloud-disk-efficiency diskplugin.csi.alibabacloud.com 4d20h
alicloud-disk-essd diskplugin.csi.alibabacloud.com 4d20h
alicloud-disk-essd diskplugin.csi.alibabacloud.com 4d20h
alicloud-disk-topology diskplugin.csi.alibabacloud.com 4d20h
|
创建应用
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
|
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: alicloud-disk-efficiency-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
storageClassName: alicloud-disk-efficiency
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.17
ports:
- containerPort: 80
volumeMounts:
- name: alicloud-disk-efficiency-pvc
mountPath: "/data"
volumes:
- name: alicloud-disk-efficiency-pvc
persistentVolumeClaim:
claimName: alicloud-disk-efficiency-pvc
|
storage: 20Gi
申请的磁盘空间大小最少20G
查看pvc
1
2
3
|
➜ ~ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
alicloud-disk-efficiency-pvc Bound disk-9dc00157-1591-11ea-9985-00163e0e39ac 20Gi RWO alicloud-disk-efficiency 2m14s
|
查看 pv
1
2
3
|
➜ ~ kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
disk-9dc00157-1591-11ea-9985-00163e0e39ac 20Gi RWO Delete Bound kube-system/alicloud-disk-efficiency-pvc alicloud-disk-efficiency 3m9s
|
查看pod状态
1
2
3
|
➜ ~ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-54fdbdf4dc-5bvpz 1/1 Running 0 21s
|
查看pod 磁盘挂载情况
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
➜ ~ kubectl exec nginx-54fdbdf4dc-5bvpz -- df -ah
Filesystem Size Used Avail Use% Mounted on
overlay 50G 4.5G 43G 10% /
proc 0 0 0 - /proc
tmpfs 64M 0 64M 0% /dev
devpts 0 0 0 - /dev/pts
sysfs 0 0 0 - /sys
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
cgroup 0 0 0 - /sys/fs/cgroup/systemd
cgroup 0 0 0 - /sys/fs/cgroup/cpu,cpuacct
cgroup 0 0 0 - /sys/fs/cgroup/net_cls,net_prio
cgroup 0 0 0 - /sys/fs/cgroup/blkio
cgroup 0 0 0 - /sys/fs/cgroup/perf_event
cgroup 0 0 0 - /sys/fs/cgroup/devices
cgroup 0 0 0 - /sys/fs/cgroup/freezer
cgroup 0 0 0 - /sys/fs/cgroup/memory
cgroup 0 0 0 - /sys/fs/cgroup/hugetlb
cgroup 0 0 0 - /sys/fs/cgroup/pids
cgroup 0 0 0 - /sys/fs/cgroup/cpuset
mqueue 0 0 0 - /dev/mqueue
/dev/vdb 20G 45M 20G 1% /data
...
|
可以看到/dev/vdb 20G 45M 20G 1% /data
已mount进来
查看管理后台
查看CSI组件
provisinoer
1
2
3
|
➜ kubectl -n kube-system get sts csi-provisioner
NAME READY AGE
csi-provisioner 1/1 4d16h
|
plugin
1
2
3
|
➜kubectl -n kube-system get ds csi-plugin
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
csi-plugin 4 4 4 4 4 <none> 4d16h
|
删除
1
|
kubectl delete -f nginx.yaml
|
参考
http://newto.me/k8s-csi-design/