【云原生】openebs-device+cstor存储方案部署
要配置使用 OpenEBS 的 device+cStor 存储方案,需要完成 cStor 池的创建、存储类定义等步骤。cStor 是 OpenEBS 提供的高性能块存储解决方案,基于存储设备构建,支持快照、克隆等高级功能。以下是详细配置步骤:
一、前提条件
1. 节点准备:
Kubernetes 集群(1.21+ 版本,本文k8s版本为1.28.2)
每个节点上有至少一块空闲的块设备(未格式化且未挂载)
安装 OpenEBS(参考官方文档):
kubectl apply -f https://openebs.github.io/charts/openebs-operator.yaml
2. 验证 OpenEBS 组件:
kubectl get pods -n openebs
确保 cstor-operator
、openebs-ndm
等组件正常运行(STATUS=Running
)。
二、配置步骤
1. 发现并标记存储设备
OpenEBS 的 NDM(Node Disk Manager)会自动发现节点上(openebs-ndm运行的节点)的块设备,需标记可用设备供 cStor 使用。
(1)查看发现的设备(存在污点的master节点除外):
kubectl get blockdevices -n openebs
输出示例:
NAME NODENAME SIZE CLAIMSTATE STATUS blockdevice-123... slave01 107374182400 Unclaimed Active blockdevice-876... slave02 107374182400 Unclaimed Active
(2)标记设备为 "cstor" 可用:
kubectl label blockdevices -n openebs blockdevice-12345678... openebs.io/block-device-type=cstor
kubectl label blockdevices -n openebs blockdevice-87654321... openebs.io/block-device-type=cstor
2. 安装cstor-operator
kubectl apply -f https://openebs.github.io/charts/cstor-operator.yaml
# 若registry.k8s.io镜像仓库无法访问# 方案一:
可以 wget https://openebs.github.io/charts/cstor-operator.yaml 到本地
# 将镜像中registry.k8s.io替换为k8s.mirror.nju.edu.cn
# 然后 kubectl apply -f cstor-operator.yaml# 方案二:
# 或者在各节点containered仓库配置
sudo vi /etc/containerd/config.toml
# 添加如下配置[plugins."io.containerd.grpc.v1.cri".registry.mirrors."registry.k8s.io"] # registry.k8s.ioendpoint = ["https://k8s.mirror.nju.edu.cn"]# 再reload、restart containered
sudo systemctl daemon-reload
sudo systemctl restart containerd
3. 验证是否安装成功
kubectl get crd | grep cstor
4. 创建 cStor 池(CStorPoolCluster)
apiVersion: cstor.openebs.io/v1
kind: CStorPoolCluster
metadata:name: cstor-poolnamespace: openebs
spec:pools:# 02节点的池配置- nodeSelector:kubernetes.io/hostname: hy02 # 目标节点dataRaidGroups:- blockDevices:# 02节点的块设备名称- blockDeviceName: blockdevice-6710671d199cc923f5d05d72a16f8e51poolConfig:# 单盘必须用 stripe;mirror 需至少 2 块盘;raidz 需至少 3 块盘dataRaidGroupType: stripe# 可选:开启厚置备(默认 false,即 thin provision)thickProvision: false# 可选:压缩(默认 off,可选 lz)compression: "off"# 03节点的池配置- nodeSelector:kubernetes.io/hostname: hy03 # 目标节点dataRaidGroups:- blockDevices:# 03节点的块设备名称- blockDeviceName: blockdevice-1e62f0264d7ceb5c4b6232d67e0d1915poolConfig:# 单盘必须用 stripedataRaidGroupType: stripethickProvision: falsecompression: "off"
(1)应用配置
kubectl apply -f cstor-pool.yaml
(2)验证 cStor 池状态
# 查看池集群
kubectl get cspc -n openebs
# 查看单个池状态
kubectl get cspi -n openebs
三、创建存储类(StorageClass)
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:name: openebs-cstor
provisioner: cstor.csi.openebs.io
parameters:cas-type: cstorcstorPoolCluster: cstor-pool # 对应你的 CSPC 名称replicaCount: "2" # 数据副本数(建议与节点数一致)
allowVolumeExpansion: true
应用配置
kubectl apply -f cstor-sc.yaml
四、使用:创建PVC、PV即可
自动创建pv和pvc绑定
亲测有效哦,如果文章中有什么问题,欢迎大家批评指正!!!