原理

1.csi插件生成/var/lib/kubelet/plugins/<driver>/csi.sock
2.node-driver-registrar 组件会将 CSI 插件的信息注册到:/var/lib/kubelet/plugins_registry/ 中
3.kubelet 发现了这个注册信息之后,就会尝试通过 socket 主动连接插件,并调用多个标准 gRPC 接口:例如NodeGetInfo
4.kubelet 根据 NodeGetInfo 的返回,创建或更新 CSINode 对象,用于调度决策(比如拓扑感知调度)。
实践1:用kubelet配置的目录信息
实践时发现,kubelet会有如下日志:
1
| 6月 06 16:47:57 kubelet[3225884]: I0606 16:47:57.955007 3225884 csi_plugin.go:99] kubernetes.io/csi: Trying to validate a new CSI Driver with name: <driverName> endpoint: /xxx/plugins/<driverName>/csi.sock versions: 1.0.0
|
以二进制方式部署的lvm-localpv有如下日志:
1 2 3
| 6月 06 16:47:57 localpv[3209981]: I0606 16:47:57.955959 3209981 grpc.go:72] GRPC call: /csi.v1.Node/NodeGetInfo requests {} 6月 06 16:47:57 cdp-10-191-193-6 localpv[3209981]: I0606 16:47:57.960667 3209981 grpc.go:81] GRPC response: {"accessible_topology":{"segments":{"openebs.io/nodename":"node0"}},"node_id":"node0"}
|
然后csinode确实更新了
然后node的annotation也确实更新了
1 2 3 4 5
| apiVersion: v1 kind: Node metadata: annotations: csi.volume.kubernetes.io/nodeid: '{"<driverName>":"node0","<anotherDriverName>":"xxx"}'
|
实践2:用kubelet配置的目录信息
1.删除/xxx/plugins/<driverName>/csi.sock
node的annotation信息还在
csinode上的信息也还在
2.在1的基础上,删除`/xxx/plugins_registry/-reg.sock
node的annotation信息被删了
csinode上的信息也被删了
但是,是谁删的呢?没在kubelet上看到相关日志
实践3:用自定义的目录信息
背景
localpv进程和node-driver-registrar进程不想使用kubelet进程配置的目录,想使用自定义的目录
前提条件
1 2 3 4 5 6 7 8 9 10 11
| ll /vdata/storage/plugins 空 ll /vdata/storage/plugins_registry 空
ll /xxx/plugins xxx为kubelet进程配置里面的 空 ll /xxx/plugins_registry xxx为kubelet进程配置里面的 空
node的annotation没有driver信息 csinode的spec下没有driver信息
localpv进程连接/vdata/storage相关目录 node-driver-registrar进程连接/vdata/storage相关目录
|
步骤
1.重启主机上的localpv进程
/vdata/storage/plugins/<driverName>/csi.sock 自动生成
2.重启主机上的node-driver-registrar进程
/vdata/storage/plugins_registry/<driverName>-reg.sock自动生成
3.创建软链接
1
| ln -s /vdata/storage/plugins_registry/<driverName>-reg.sock /xxx/plugins_registry/<driverName>-reg.sock
|
未重启kubelet
此时,kubelet打印处日志:
1
| 6月 06 18:16:45 kubelet[3225884]: I0606 18:16:45.956052 3225884 csi_plugin.go:99] kubernetes.io/csi: Trying to validate a new CSI Driver with name: <driverName> endpoint: /vdata/storage/plugins/local.csi.paas.cucloud/csi.sock versions: 1.0.0
|
locallv进程的日志:
1 2
| 6月 06 16:47:57 localpv[3209981]: I0606 16:47:57.955959 3209981 grpc.go:72] GRPC call: /csi.v1.Node/NodeGetInfo requests {} 6月 06 16:47:57 localpv[3209981]: I0606 16:47:57.960667 3209981 grpc.go:81] GRPC response: {"accessible_topology":{"segments":{"openebs.io/nodename":"node0"}},"node_id":"node0"}
|
node-driver-registrar进程的日志:
1 2
| 6月 06 18:16:45 node-driver-registrar[3342604]: I0606 18:16:45.955789 3342604 main.go:98] "Received GetInfo call" request="&InfoRequest{}" 6月 06 18:16:46 node-storage-driver-registrar[3342604]: I0606 18:16:46.000749 3342604 main.go:110] "Received NotifyRegistrationStatus call" status="&RegistrationStatus{PluginRegistered:true,Error:,}"
|
csinode上的信息有了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| apiVersion: storage.k8s.io/v1 kind: CSINode metadata: name: node0 ownerReferences: - apiVersion: v1 kind: Node name: node0 uid: c7a8993b-40ab-4641-849f-6ac40d8a6750 resourceVersion: "33527" uid: 7ac73448-c503-40b6-bed4-90a3285619da spec: drivers: - name: <driverName> nodeID: node0 topologyKeys: - openebs.io/nodename
|
node的annotation信息也有了
1 2 3 4 5
| apiVersion: v1 kind: Node metadata: annotations: csi.volume.kubernetes.io/nodeid: '{"<driverName>":"node0"}'
|
实践4:用自定义的目录信息
背景
localpv进程和node-driver-registrar进程不想使用kubelet进程配置的目录,想使用自定义的目录
前提条件
1 2 3 4 5 6 7 8 9 10 11
| ll /vdata/storage/plugins 空 ll /vdata/storage/plugins_registry 空
ll /xxx/plugins xxx为kubelet进程配置里面的 空 ll /xxx/plugins_registry xxx为kubelet进程配置里面的 空
node的annotation没有driver信息 csinode的spec下没有driver信息
localpv进程连接/vdata/storage相关目录 node-driver-registrar进程连接/vdata/storage相关目录
|
快捷命令
1
| systemctl list-units |grep storage
|
步骤
1.重启主机上的node-driver-registrar进程
该进程连不上csi.sock 一直在重启
1 2 3 4 5 6 7 8 9 10 11
| 6月 09 09:55:32 node-driver-registrar[2035069]: I0609 09:55:32.340043 2035069 main.go:152] "Version" version="v0.0.1" 6月 09 09:55:32 node-driver-registrar[2035069]: I0609 09:55:32.340128 2035069 main.go:153] "Running node-driver-registrar" mode="" 6月 09 09:55:32 node-driver-registrar[2035069]: I0609 09:55:32.340156 2035069 main.go:175] "Created directory for pluginRegistrationPath successfully" pluginRegistrationPath="/vdata/storage/plugins_registry/" 6月 09 09:55:32 node-driver-registrar[2035069]: I0609 09:55:32.340176 2035069 main.go:181] "Attempting to open a gRPC connection" csiAddress="/vdata/storage/plugins/<driverName>/csi.sock" 6月 09 09:55:32 node-driver-registrar[2035069]: I0609 09:55:32.340211 2035069 connection.go:234] "Connecting" address="unix:///vdata/storage/plugins/<driverName>/csi.sock" 6月 09 09:55:42 node-driver-registrar[2035069]: I0609 09:55:42.340927 2035069 connection.go:253] "Still connecting" address="unix:///vdata/storage/plugins/<driverName>/csi.sock" 6月 09 09:55:52 node-driver-registrar[2035069]: I0609 09:55:52.340933 2035069 connection.go:253] "Still connecting" address="unix:///vdata/storage/plugins/<driverName>/csi.sock" 6月 09 09:56:02 node-driver-registrar[2035069]: I0609 09:56:02.340838 2035069 connection.go:253] "Still connecting" address="unix:///vdata/storage/plugins/<driverName>/csi.sock" 6月 09 09:56:02 node-driver-registrar[2035069]: E0609 09:56:02.340965 2035069 main.go:185] "Error connecting to CSI driver" err="context deadline exceeded" 6月 09 09:56:02 systemd[1]: node-driver-registrar.service: Main process exited, code=exited, status=1/FAILURE
|
2.重启主机上的localpv进程
/vdata/storage/plugins/<driverName>/csi.sock 自动生成
node-driver-registrar进程正常启动,不会再退出了
/vdata/storage/plugins_registry/<driverName>-reg.sock自动生成
3.创建软链接
1
| ln -s /vdata/storage/plugins_registry/<driverName>-reg.sock /xxx/plugins_registry/<driverName>-reg.sock
|
未重启kubelet
此时,kubelet打印处日志:
1 2
| 6月 09 10:02:14 kubelet[3225884]: I0609 10:02:14.064767 3225884 csi_plugin.go:99] kubernetes.io/csi: Trying to validate a new CSI Driver with name: <driverName> endpoint: /vdata/storage/plugins/<driverName>/csi.sock versions: 1.0.0
|
locallv进程的日志:
1 2 3
| 6月 09 10:02:14 localpv[2443179]: I0609 10:02:14.066717 2443179 grpc.go:72] GRPC call: /csi.v1.Node/NodeGetInfo requests {} 6月 09 10:02:14 localpv[2443179]: I0609 10:02:14.073840 2443179 grpc.go:81] GRPC response: {"accessible_topology":{"segments":{"openebs.io/nodename":"node0"}},"node_id":"node0"}
|
node-driver-registrar进程的日志:
1 2
| 6月 09 10:02:14 node-driver-registrar[2447943]: I0609 10:02:14.064271 2447943 main.go:98] "Received GetInfo call" request="&InfoRequest{}" 6月 09 10:02:14 node-driver-registrar[2447943]: I0609 10:02:14.116255 2447943 main.go:110] "Received NotifyRegistrationStatus call" status="&RegistrationStatus{PluginRegistered:true,Error:,}"
|
csinode上的信息有了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| apiVersion: storage.k8s.io/v1 kind: CSINode metadata: name: node0 ownerReferences: - apiVersion: v1 kind: Node name: node0 uid: c7a8993b-40ab-4641-849f-6ac40d8a6750 resourceVersion: "33527" uid: 7ac73448-c503-40b6-bed4-90a3285619da spec: drivers: - name: <driverName> nodeID: node0 topologyKeys: - openebs.io/nodename
|
node的annotation信息也有了
1 2 3 4 5
| apiVersion: v1 kind: Node metadata: annotations: csi.volume.kubernetes.io/nodeid: '{"<driverName>":"node0"}'
|