FlexVolume介绍
1. FlexVolume介绍
Flexvolume提供了一种扩展k8s存储插件的方式,用户可以自定义自己的存储插件。类似的功能的实现还有CSI的方式。Flexvolume在k8s 1.8+以上版本提供GA功能版本。
2. 使用方式
在每个node节点安装存储插件二进制,该二进制实现flexvolume的相关接口,默认存储插件的存放路径为/usr/libexec/kubernetes/kubelet-plugins/volume/exec/<vendor~driver>/<driver>
。
其中vendor~driver
的名字需要和pod中flexVolume.driver的字段名字匹配,该字段名字通过/
替换~
。
例如:
-
path:/usr/libexec/kubernetes/kubelet-plugins/volume/exec/foo~cifs/cifs
-
pod中flexVolume.driver:foo/cifs
3. FlexVolume接口
节点上的存储插件需要实现以下的接口。
3.1. init
<driver executable> init
3.2. attach
<driver executable> attach <json options> <node name>
3.3. detach
<driver executable> detach <mount device> <node name>
3.4. waitforattach
<driver executable> waitforattach <mount device> <json options>
3.5. isattached
<driver executable> isattached <json options> <node name>
3.6. mountdevice
<driver executable> mountdevice <mount dir> <mount device> <json options>
3.7. unmountdevice
<driver executable> unmountdevice <mount device>
3.8. mount
3.9. unmount
3.10. 插件输出
4. 示例
4.1. pod的yaml文件内容
nginx-nfs.yaml
相关参数为flexVolume.driver等。
4.2. 插件脚本
nfs脚本实现了flexvolume的接口。
/usr/libexec/kubernetes/kubelet-plugins/volume/exec/k8s~nfs/nfs。
参考:
- https://github.com/kubernetes/community/blob/master/contributors/devel/sig-storage/flexvolume.md
- https://github.com/kubernetes/examples/tree/master/staging/volumes/flexvolume
- https://github.com/kubernetes/examples/blob/master/staging/volumes/flexvolume/nginx-nfs.yaml
- https://github.com/kubernetes/examples/blob/master/staging/volumes/flexvolume/nfs
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.
最后修改 December 25, 2022: deploy by blog source (a162b04)