k8s-cinder-csi-plugin
背景
CSI Cinder Plugin是兼容 CSI Specification 的Driver,Container Orchestrators使用该Driver管理openstack cinder volume的生命周期。 社区的cinder-csi-plugin是基于云上实现的,也就是说kubernetes环境必须安装在openstack环境中,才可以使用openstack cinder创建的卷。这种方式局限性太大了,由此开发一个Cinder CSI Driver,不限制K8s部署环境,实现pod挂载openstack cinder卷。此插件依赖golang-os-brick进行挂载后端卷,目前cinder后端驱动只支持ceph rbd。
部署
部署方式支持两种,一种是manifests目录下的清单文件,另一种是helm chart
命令行参数
除了标准的klog标志集外,cinder-csi-plugin还接受以下命令行参数:
- --endpoint 这个参数是必须的,gRPC服务器代理的端点将用来连接到这个CSI插件,通常是一个本地unix套接字。manifests清单中默认是
unix://csi/csi.sock
,它是通过 CSI_ENDPOINT
环境变量提供的。
- --cloud-config 这个参数是必须的,driver config文件的路径。该文件的格式在driver config配置中指定。manifests清单中默认是
/etc/config/cloud.conf
,它是通过CLOUD_CONFIG
环境变量提供的
- --cluster 这个参数是可选的,集群所在插件的标识符。
驱动器配置
对于驱动程序配置,参数必须通过在$CLOUD_CONFIG
环境变量中指定的配置文件传递。配置文件中支持以下部分
Global
用于Cinder CSI Plugin通过Openstack keystone 认证,必需的参数需要在文件的[Global]
部分传递,有关所有支持的参数,请参阅Global部分
Block Storage
这些配置选项属于块存储,应该出现在$CLOUD_CONFIG
文件的[BlockStorage]
部分
- node-volume-attach-limit 可选的,配置节点可挂载卷的数目,默认值为
256
- rescan-on-resize 可选的,设置为
true
,在扩展文件系统之前重新扫描块设备并验证其大小,默认值为false
- ignore-volume-az 可选的,启用
Topology
特性后,PV卷节点亲和性默认填充卷可访问拓扑,默认值为false
- force-snapshot 可选的,设置为
true
,用于pod在运行状态下对pvc创建快照,需手动在pod中执行sync
命令,将改写的数据落盘,否则,会造成pod数据丢失。设置为false
,在对pvc创建快照时,需删除或停止pod,默认值为false
Using the manifests
部署插件所需的所有manifests
都可以在manifests目录下找到
$CLOUD_CONFIG
文件通过kubernetes secret传递给cinder csi driver
- 创建
cloud-config
secret
- 使用base64编码你的
$CLOUD_CONFIG
内容
$ base64 -w 0 $CLOUD_CONFIG
- 更新
manifests/csi-secret-cinderplugin.yaml
中的cloud.conf
- 创建secret
$ kubectl apply -f manifests/csi-secret-cinderplugin.yaml
- 后端驱动为ceph,还需创建
cinder-volume-rbd-keyring
secret
- 使用base64编码cinder对接的ceph keyring
$ base64 -w 0 cinder-volume-rbd-keyring
- 将编码后的内容替换为
manifests/cinder-volume-rbd-keyring.yaml
文件中的key
- 创建secret
$ kubectl apply -f manifests/csi-secret-cinderplugin.yaml
secret 创建完成之后,控制器插件和节点插件可以使用各自的清单部署
$ kubectl apply -f manifests/cinder-csi-plugin/
这将创建一组cluster roles、cluster role bindings和statefulsets等来与openstack(cinder)通信。有关已创建对象的详细列表,请查看目录中的yaml文件。
$ kubectl get pod -n kube-system
cinder-csi-plugin-controllerplugin-59cc8d6865-fdk9j 6/6 Running 3 121m
cinder-csi-plugin-nodeplugin-78dw2 3/3 Running 0 121m
cinder-csi-plugin-nodeplugin-gj69l 3/3 Running 0 121m
cinder-csi-plugin-nodeplugin-zjbpf 3/3 Running 0 121m
获取集群中运行的CSI驱动程序的信息
$ kubectl get csidrivers.storage.k8s.io
NAME ATTACHREQUIRED PODINFOONMOUNT MODES AGE
cinder.csi.openstack.org true true Persistent,Ephemeral 122m
Using the Helm chart
创建K8s cloud-config Secret,替换下面的cloud-config
内容
secret:
enabled: true
create: true
name: cinder-csi-cloud-config
data:
cloud-config: |-
[Global]
username = admin
password = password
os-endpoint-type = public
domain-name = default
tenant-name = admin
auth-url = http://keystone.openstack.svc.cluster.local/v3
region = RegionOne
创建K8s cinder-volume-rbd-keyring Secret,替换下面的keyring
内容
ceph:
enabledCephAuth: true
keyringName: cinder-volume-rbd-keyring
keyring: W2NsaWVudC5jaW5kZXJdCiAgICBrZXkgPSBBUUI0QTZwaDlNZFREUkFBZEZCdmFPYXR6a2xWUlJBcWtaSmtCZz09Cg==
使用下面的命令安装charts
helm install cinder-csi-plugin charts/k8s-cinder-csi-plugin -n kube-system
Supported Features
Supported Parameters
Parameter Type |
Parameter Name |
Default |
Description |
StorageClass parameters |
availability |
nova |
String. Volume Availability Zone |
StorageClass parameters |
type |
Empty String |
String. Name/ID of Volume type. Corresponding volume type should exist in cinder |
VolumeSnapshotClass parameters |
force-create |
false |
Enable to support creating snapshot for a volume in in-use status |
Inline Volume volumeAttributes |
capacity |
1Gi |
volume size for creating inline volumes |
Inline Volume VolumeAttributes |
type |
Empty String |
Name/ID of Volume type. Corresponding volume type should exist in cinder |
Use the sample