免费网站建站模板/昆明百度关键词优化
volume加载过程
1.用户创建一个包含PVC的Pod。
2.PVController会不断观察ApiServer,负责PV和PVC绑定(包括创建新PV-)。
3.通过Scheduler完成调度功能。
4.PV还没有被挂载(Attach)到选定NODE,ADController就会调用VolumePlugin,把远端的Volume挂载到目标节点中的设备上(如:/dev/vdb)。
5.当VolumManager它就会执行mount操作,将本地设备挂载到Pod在节点上的一个子目录中。同时它也可能会做一些像格式化、是否挂载到GlobalPath等这样的附加操作。
但–enable-controller-attach-detach=false时会执行AD操作
6.绑定操作,就是将已经挂载到本地的Volume映射到容器中。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-EUpDmDCM-1585918267346)(media/923e0173735a88ebe521753dfe78af6a.png)]
主要相关部件
controller
-
PV Controller:负责 PV/PVC 的绑定、生命周期管理,并根据需求进行数据卷的
Provision/Delete 操作; -
AD Controller:负责存储设备的 Attach/Detach 操作,将设备挂载到目标节点;
kubelet
Volume Manager:管理卷的 Mount/Unmount
操作、卷设备的格式化以及挂载到一些公用目录上的操作;
和 AD Controller 一样包含有 desireStateofWorld 以及
actualStateofWorld,可自己执行A/D操作
Volume Plugins
有部件分别对接API SERVER,CONTROLLER及kubelet
它主要是对上面所有挂载功能的实现。
PV Controller
PVC / PV绑定检查
1、检查VolumeMode(filesystem/block) 是否一致
2、如PVC 中定义了 LabelSelector 之后,我们就会选择那些有 Label 并且与 PVC 的
LabelSelector 相匹配的 PV 进行绑定;
3、StorageClassName 的检查
4、AccessMode 检查:“ReadWriteOnce”、“RearWriteMany” 这样的标签
5、Size 的检查 ,PVC SIZING<=PV
ClaimWorker
实现的是 PVC 的状态迁移
pv.kubernetes.io/bind-completed-true代表PV bind完成
VolumeWorker
依托ClaimRef 标签来判断PV状态并进行相关处理,如进入queue
available,bound,unbound,released
Attach/Detach Controller
DesiredStateofWorld
-
管理集群中预期要达到的数据卷的挂载状态
-
每一个 Worker 进行定义,包括 Worker 所包含的 Volume 以及一些试图挂载的信息
ActualStateOfWorld
-
集群内部实际存在的数据卷挂载状态
-
所有的 Volume 进行一次定义,包括每一个 Volume
期望挂载到哪个节点上、挂载的状态
核心逻辑
-
desiredStateOfWorldPopulator
-
同步集群的一些数据以及 DSW、ASW 数据的更新
-
Reconcile
-
-
根据 DSW 和 ASW 对象的状态做状态同步,过程中执行 Attach、Detach 等操作
-
依托infomer进行数据同步
Volume Manager
和 AD Controller 一样包含有 desireStateofWorld 以及 actualStateofWorld
volumePluginManager 对象
-
负责节点上插件的管理
-
–enable-controller-attach-detach=true
-
default true
-
Enables the Attach/Detach controller to manage attachment/detachment of
volumes scheduled to this node, and disables kubelet from executing any
attach/detach operations (default true)
-
Volume Plugins
实际上就是 PV Controller、AD Controller 以及 Volume Manager 所调用的一个库
VolumePluginsMgr
-
PV Controller、AD Controller 以及 Volume Manager 在启动的时候会执行一个
InitPlugins 方法来对 VolumePluginsMgr 做初始化-
将In-Tree 的 Plugins 加入到插件列表中。
-
调用 Prober 的 init 方法,该方法会首先调用一个
InitWatcher,它会时刻观察着flexVolume目录 -
/usr/libexec/kubernetes/kubelet-plugins/volume/exec/
-
-
运行在kubelet
-
FlexVolume有变化,生成新的 FsNotify.Create/Delete 事件,probe进行处理
-
上层调用 refreshProbedPlugins 时,Prober 就会把这些事件进行一个更新
Flexvolume
Volume Plugins 的一个扩展,主要实现 Attach/Detach/Mount/Unmount 这些接口
以特定格式将执行文件(shell)放在node指定目录下
-
default plugin directory is
/usr/libexec/kubernetes/kubelet-plugins/volume/exec/ -
changed in kubelet via the --volume-plugin-dir flag
-
controller manager via the --flex-volume-plugin-dir flag
-
<plugindir>/<vendor~driver>/<driver>
- cifs driver, by vendor foo install the driver in subDir foo~cifs/cifs
-
https://github.com/kubernetes/community/blob/master/contributors/devel/sig-storage/flexvolume.md
Beginning in v1.8 ,可以在线动态更新
要实现的方法-部分是optional
called by Controller
-
Init
-
Attach
-
does not pass “secrets” specified in Flexvolume spec
-
如果要secrets,使用mount替代
-
-
Detach
-
Wait for attach
-
Volume is Attached
- Check the volume is attached on the node
called by kubelet
-
Init
-
Mount device
- Mount device mounts the device to a global path which individual pods
can then bind mount
- Mount device mounts the device to a global path which individual pods
-
Unmount device
-
Mount
- Mount the volume at the mount dir
-
Unmount
部分方法是controller及kubelet都call
未实现需要返回
{ "status": "Not supported", "message": "error message" }
https://github.com/AliyunContainerService/flexvolume
推荐使用DS+bind host dir 部署
Flexvolume不支持Provision操作
CSI
CSI support was introduced as alpha in Kubernetes v1.9, moved to beta in
Kubernetes v1.10, and is GA in Kubernetes v1.13
相对flexvolume
-
CSI 容器化部署的方式,支持RBAC
-
减少环境依赖,增强安全性
-
CSI 可以满足不同编排系统的需求,比如 Mesos、Swarm。
-
是通过 CRD 的形式实现的
部件
CSI Controller Server
-
控制端的功能,主要实现创建、删除、挂载、卸载等功能
-
与kube Controller 之间隔了External CSI SideCar
-
sidecar 与CSI controller server使用socket通讯
-
controller manager will communicate with the external “CSI volume
driver” through the Kubernetes API
-
level-2
-
AD Controller
-
Volume Plugins
-
External Provisioner 和 Controller Server
组合的时候就会完成数据卷的创建与删除功能; -
External Attacher 和 Controller Server 组合起来可以执行数据卷的挂载和操作;
- 它通过观察 VolumeAttachment 对象来实现状态的判断
-
External Resizer 和 Controller Server 组合起来可以执行数据卷的扩容操作;
-
External Snapshotter 和 Controller Server 组合则可以完成快照的创建和删除
Node Server
-
节点上的 mount、Unmount 功能
-
使用Unix Domain Socket与kubelet通讯
- /var/lib/kubelet/plugins/[SanitizedCSIDriverName]/csi.sock
-
Create/update a CSINodeInfo object instance for the node with the NodeID and
topology keys from accessible_topology -
Update Node API object with the CSI driver NodeID as the
csi.volume.kubernetes.io/nodeid annotation -
Create/update Node API object with accessible_topology as labels. There are
no hard restrictions on the label format
level -2
-
VolumeManager
- 调用 CSI Plugin 去做 mount 和 unmount 操作
-
VolumePlugin
- 调用 CSI Plugin 去做 mount 和 unmount 操作
-
Driver Registra
接口
-
通用管控接口
- 主要返回 CSI 的一些通用信息,像插件的名字、Driver
的身份信息、插件所提供的能力
- 主要返回 CSI 的一些通用信息,像插件的名字、Driver
-
节点管控
-
管控接口的 NodeStageVolume 和 NodeUnstageVolume 就相当于 Flexvolume 中的
MountDevice 和 UnmountDevice -
NodePublishVolume 和 NodeUnpublishVolume 就相当于 SetUp 和 TearDown
接口;
-
-
中心管控
-
CreateVolume 和 DeleteVolume
-
ControllerPublishVolume 和 ControllerUnPublishVolume 则分别是 Attach 和
Detach 的接口。
-
主要CRD 对象
-
VolumeAttachment 描述一个 Volume 卷在一个 Pod 使用中挂载、卸载的相关信息
-
AD Controller 通过CSI Attacher (k8s in-tree)创建一个 VolumeAttachment
-
而 External-attacher 则通过观察该
VolumeAttachment,根据其状态来进行挂载和卸载操作
-
-
CSIDriver,它描述了集群中所部署的 CSI Plugin 列表
-
label:attachRequired 定义一个 Plugin 是否支持 Attach
功能,主要是为了对块存储和文件存储做区分。比如文件存储不需要 Attach
操作,因此我们将该标签定义为 False -
label:podInfoOnMount 则是定义 Kubernetes 在调用 Mount 接口时是否带上
Pod 信息
-
-
CSINode,它是集群中的节点信息,由 node-driver-registrar 在启动时创建
- 新的 CSI Plugin 注册后,都会在 CSINode 列表里添加一个 CSINode 信息
registration过程
1、在启动的时候有一个约定,比如说在/var/lib/kuberlet/plugins_registry这个目录每新加一个文件
2、Node-Driver-Registrar启动时先会向CSI-Plugin发起一个接口调用GetPluginInfo,这个接口会返回CSI所监听的地址以及CSI-Plugin的一个Drivername。
3、Node-Driver-Registrar会监听GetInfo和NotifyRegistrationStatus两个接口。
4、在/var/lib/kuberlet/plugins_registry这个目录下启动一个Socket,生成一个Socket文件,例如:“diskplugin.csi.alibabacloud.com-reg.sock”
5、Kubelet通过Watcher发现这个Socket后,它会通过该Socket向Node-Driver-Registrar的GetInfo接口进行调用、接口返回CSI-Plugin的监听地址以及它的Drivername
6、Kubelet通过得到的监听地址对CSI-Plugin的NodeGetInfo接口进行调用。
7、调用成功之后,Kubelet会去更新一些状态信息,比如节点的Annotations、Labels、status.allocatable等信息,同时会创建一个CSINode对象。
8、通过对Node-Driver-Registrar的NotifyRegistrationStatus接口的调用告诉它我们已经把CSI-Plugin注册成功了。
部署
-
master
-
Controller Server Pod
-
可以多份容灾
-
-
node
-
Node Server Pod
-
Driver Registrar
-
-
CSI-Provisioner需要部署不一定是DaemonSet模式
安全
CSI 可以根据不同的阶段定义不同的 Secret 类型,比如挂载阶段的 Secret、Mount
阶段的 Secret、Provision 阶段的 Secret
POD使用主要spec
-
driver 就是定义是由哪一个插件来去实现挂载;
-
volumeHandle 主要是指示 PV 的唯一标签;
-
volumeAttribute 用于附加参数,比如 PV 如果定义的是 OSS,那么就可以在
volumeAttribute 定义 bucket、访问的地址等信息在里面; -
nodeAffinity 则可以定义一些调度信息。与 Flexvolume 类似,还可以通过 selector
和 Label 定义一些绑定条件
演进
可扩展Volume:ExpandCSIVolumes
快照和恢复:VolumeSnapshotDataSource
基于pvc复制:VolumePVCDataSource
inlineVolume,无需PV/PVC,直接在POD内定义:CSIInlineVolume
开发实现
-
external-attacher:Watches Kubernetes VolumeAttachment objects and triggers
ControllerPublish and ControllerUnpublish operations against a CSI endpoint. -
external-provisioner:Watches Kubernetes PersistentVolumeClaim objects and
triggers CreateVolume and DeleteVolume operations against a CSI endpoint. -
node-driver-registrar:Registers the CSI driver with kubelet using the
Kubelet device plugin mechanism. -
cluster-driver-registrar (Alpha):Registers a CSI Driver with the Kubernetes
cluster by creating a CSIDriver object which enables the driver to customize
how Kubernetes interacts with it. -
external-snapshotter (Alpha):Watches Kubernetes VolumeSnapshot CRD objects
and triggers CreateSnapshot and DeleteSnapshot operations against a CSI
endpoint. -
livenessprobe:May be included in a CSI plugin pod to enable the Kubernetes
Liveness Probe mechanism.