Kubernetes(K8s)_16_CSI

Kubernetes(K8s)_16_CSI

CSI

CSI(Container Storage Interface): 实现容器存储的规范

  1. 本质: Dynamic ProvisioningAttach/DetachMount/Unmount等功能的抽象
  2. CSI功能通过3个gRPC暴露服务: IdentityServer、ControllerServer、NodeServer
  3. CSI的实现仅暴露服务, 调用由部署时选择的插件代理(kubelet通过Socket调用服务)

如: CSI架构

image


CSI实现

CSI实现: CSI功能实现并与组件拼装

  1. CSI进程需包含3个gRPC, 但其部署形式不相同
  2. CSI功能实现后, 需选择对应的插件进行调用(外部才可使用)

如: CSI注册流程(注册成功后为每个节点创建个CSINode)

image

  1. kubelet通过fsnotify监听/var/lib/kubelet/plugins_registry插件目录
  2. node-driver-registrar配置节点的CSI运行环境
    • 根据参数获取CSI的Socket文件, 并调用GetPluginInfo方法获取CSI的插件信息
    • 插件目录下创建名为<CSIName>-reg.sock的Socket
  3. kubelet监听到插件目录下Socket文件创建, 完成CSI注册
    • 将监听到新建的Socket信息存储内存中的desiredStateOfWorld
    • Reconciler协程周期性完成CSI注册(周期性启动)
      • 每次启动对比actualStateOfWorlddesiredStateOfWorld以获取需处理的CSI
      • 调用需注册的node-driver-registrarGetInfo方法获取CSI元数据相关信息
      • 基于元数据信息调用CSI的NodeGetInfo方法获取节点相关信息
      • 根据获取信息通过API Server更新节点的Annotations
      • 成功更新节点信息后通过API Server创建/更新CSINode
      • 调用node-driver-registrarNotifyRegistrationStatus方法通知注册结果

// 注册完成后Reconciler协程同样周期性对比状态以获取需处理事件(向期望状态收敛)


CSI接口

IdentityServer: 提供插件信息(名称和功能等元数据)

  1. node-driver-registrar插件以DaemonSet形式部署在相同Pod内
// https://github1s.com/container-storage-interface/spec/blob/master/lib/go/csi/csi.pb.go#L6251-L6256

// IdentityServer
type IdentityServer interface {
    GetPluginInfo(context.Context, *GetPluginInfoRequest) (*GetPluginInfoResponse, error)
    GetPluginCapabilities(context.Context, *GetPluginCapabilitiesRequest)  (*GetPluginCapabilitiesResponse, error)
    Probe(context.Context, *ProbeRequest) (*ProbeResponse, error)
}

ControllerServer: 卷的事件处理(集群级别)

  1. external-XXX插件以选举Deployment或副本数为1的StatefulSet形式部署在相同Pod内
  2. 属于有状态服务, 但与部署节点无关
// https://github1s.com/container-storage-interface/spec/blob/master/lib/go/csi/csi.pb.go#L6505-L6521

// ControllerServer CSI对应的Controller需实现的API
type ControllerServer interface {
    CreateVolume(context.Context, *CreateVolumeRequest) (*CreateVolumeResponse, error)
    DeleteVolume(context.Context, *DeleteVolumeRequest) (*DeleteVolumeResponse, error)

    ControllerPublishVolume(context.Context, *ControllerPublishVolumeRequest) (*ControllerPublishVolumeResponse, error)
    ControllerUnpublishVolume(context.Context, *ControllerUnpublishVolumeRequest) (*ControllerUnpublishVolumeResponse, error)

    ValidateVolumeCapabilities(context.Context, *ValidateVolumeCapabilitiesRequest) (*ValidateVolumeCapabilitiesResponse, error)
    ListVolumes(context.Context, *ListVolumesRequest) (*ListVolumesResponse, error)
    GetCapacity(context.Context, *GetCapacityRequest) (*GetCapacityResponse, error)
    ControllerGetCapabilities(context.Context, *ControllerGetCapabilitiesRequest) (*ControllerGetCapabilitiesResponse, error)
    
    CreateSnapshot(context.Context, *CreateSnapshotRequest) (*CreateSnapshotResponse, error)
    DeleteSnapshot(context.Context, *DeleteSnapshotRequest) (*DeleteSnapshotResponse, error)
    ListSnapshots(context.Context, *ListSnapshotsRequest) (*ListSnapshotsResponse, error)
    
    ControllerExpandVolume(context.Context, *ControllerExpandVolumeRequest) (*ControllerExpandVolumeResponse, error)
    ControllerGetVolume(context.Context, *ControllerGetVolumeRequest) (*ControllerGetVolumeResponse, error)
    ControllerModifyVolume(context.Context, *ControllerModifyVolumeRequest) (*ControllerModifyVolumeResponse, error)
}

NodeServer: 节点存储功能

  1. node-driver-registrar插件以DaemonSet形式部署在相同Pod内
// https://github1s.com/container-storage-interface/spec/blob/master/lib/go/csi/csi.pb.go#L7165-L7175

// NodeServer 节点存储服务需实现的API
type NodeServer interface {
    NodeStageVolume(context.Context, *NodeStageVolumeRequest) (*NodeStageVolumeResponse, error)
    NodeUnstageVolume(context.Context, *NodeUnstageVolumeRequest) (*NodeUnstageVolumeResponse, error)
    NodePublishVolume(context.Context, *NodePublishVolumeRequest) (*NodePublishVolumeResponse, error)
    NodeUnpublishVolume(context.Context, *NodeUnpublishVolumeRequest) (*NodeUnpublishVolumeResponse, error)
    NodeGetVolumeStats(context.Context, *NodeGetVolumeStatsRequest) (*NodeGetVolumeStatsResponse, error)
    NodeExpandVolume(context.Context, *NodeExpandVolumeRequest) (*NodeExpandVolumeResponse, error)
    NodeGetCapabilities(context.Context, *NodeGetCapabilitiesRequest) (*NodeGetCapabilitiesResponse, error)
    NodeGetInfo(context.Context, *NodeGetInfoRequest) (*NodeGetInfoResponse, error)
}

CSI插件

Kubernetes社区维护的常用插件

插件说明
node-driver-registrar注册CSI
external-provisioner调用CSI实现Dynamic Provisioner
external-attacher调用CSI实现Attach/Detach
external-snapshotter调用CSI实现快照
external-resizer调用CSI实现扩容
external-health-monitor卷的健康检查
  1. 插件均以SideCar形式与CSI部署在相同Pod内
  2. node-driver-registrar是必需组件, 其他扩展插件可视功能需求选择
  3. 扩展插件通过调用CSI实现功能时, 均是调用CSI中的ControllerServer

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值