kubernetes配置后端存储 rook-ceph
作者:互联网
一 Rook概述
1.1 Ceph简介
Ceph是一种高度可扩展的分布式存储解决方案,提供对象、文件和块存储。在每个存储节点上,将找到Ceph存储对象的文件系统和Ceph OSD(对象存储守护程序)进程。在Ceph集群上,还存在Ceph MON(监控)守护程序,它们确保Ceph集群保持高可用性。
更多Ceph介绍参考:https://www.cnblogs.com/itzgr/category/1382602.html
1.2 Rook简介
Rook 是一个开源的cloud-native storage编排, 提供平台和框架;为各种存储解决方案提供平台、框架和支持,以便与云原生环境本地集成。目前主要专用于Cloud-Native环境的文件、块、对象存储服务。它实现了一个自我管理的、自我扩容的、自我修复的分布式存储服务。
Rook支持自动部署、启动、配置、分配(provisioning)、扩容/缩容、升级、迁移、灾难恢复、监控,以及资源管理。为了实现所有这些功能,Rook依赖底层的容器编排平台,例如 kubernetes、CoreOS 等。。
Rook 目前支持Ceph、NFS、Minio Object Store、Edegefs、Cassandra、CockroachDB 存储的搭建。
Rook机制:
Rook 提供了卷插件,来扩展了 K8S 的存储系统,使用 Kubelet 代理程序 Pod 可以挂载 Rook 管理的块设备和文件系统。
Rook Operator 负责启动并监控整个底层存储系统,例如 Ceph Pod、Ceph OSD 等,同时它还管理 CRD、对象存储、文件系统。
Rook Agent 代理部署在 K8S 每个节点上以 Pod 容器运行,每个代理 Pod 都配置一个 Flexvolume 驱动,该驱动主要用来跟 K8S 的卷控制框架集成起来,每个节点上的相关的操作,例如添加存储设备、挂载、格式化、删除存储等操作,都有该代理来完成。
更多参考如下官网:
https://rook.io
https://ceph.com/
二 Rook部署
2.1 前期规划
请自动创建好kubernetes集群
集群版本 v1.21.5
内核要求
RBD
lsmod|grep rbd
CephFS
如果你想使用cephfs,内核最低要求是4.17。
磁盘 sdb
主机内核 5.4.182-1.el7.elrepo.x86_64
集群节点 estarhaohao-centos7-master01 estarhaohao-centos7-master02 estarhaohao-centos7-master03
用到的所有文件请自行到我的gitee仓库拉取https://gitee.com/estarhaohao/rook.git
2.2 获取YAML
[root@k8smaster01 ~]# git clone https://gitee.com/estarhaohao/rook.git
2.3 配置节点标签
[root@estarhaohao-centos7-master01 ~]# kubectl label nodes {estarhaohao-centos7-master01,estarhaohao-centos7-master02,estarhaohao-centos7-master03} app.rook.role=csi-provisioner app.rook.plugin=csi app.rook=storage ceph-mon=enabled ceph-osd=enabled ceph-mgr=enabled
2.4 部署Rook Operator
[root@estarhaohao-centos7-master01 ceph]# kubectl apply -f common.yaml
[root@estarhaohao-centos7-master01 ceph]# kubectl apply -f crds.yaml #创建资源
[root@estarhaohao-centos7-master01 ceph]# kubectl apply -f operator.yaml
configmap/rook-ceph-operator-config created
deployment.apps/rook-ceph-operator created
[root@estarhaohao-centos7-master01 ceph]# kubectl get pod -n rook-ceph
NAME READY STATUS RESTARTS AGE
rook-ceph-operator-56496b9f8f-dblnq 1/1 Running 0 3m37s
rook-discover-2jp7z 1/1 Running 0 2m53s
rook-discover-hqq27 1/1 Running 0 2m53s
rook-discover-sx8c6 1/1 Running 0 2m53s
创建成功后创建cluster
2.5 创建cluster
[root@estarhaohao-centos7-master01 ceph]# kubectl get pod -n rook-ceph
[root@estarhaohao-centos7-master01 ceph]# kubectl get pod -n rook-ceph
NAME READY STATUS RESTARTS AGE
csi-cephfsplugin-mwfg8 3/3 Running 0 5m53s
csi-cephfsplugin-provisioner-6446d9c9df-4r5xq 6/6 Running 0 5m52s
csi-cephfsplugin-provisioner-6446d9c9df-rkd4k 6/6 Running 0 5m52s
csi-cephfsplugin-vrlwm 3/3 Running 0 5m53s
csi-cephfsplugin-xfm8n 3/3 Running 0 5m53s
csi-rbdplugin-d87pk 3/3 Running 0 5m54s
csi-rbdplugin-k292p 3/3 Running 0 5m54s
csi-rbdplugin-provisioner-6998bd5986-j7729 6/6 Running 0 5m53s
csi-rbdplugin-provisioner-6998bd5986-rp2wk 6/6 Running 0 5m53s
csi-rbdplugin-r56c2 3/3 Running 0 5m54s
rook-ceph-crashcollector-estarhaohao-centos7-master01-564fhkv28 1/1 Running 0 4m7s
rook-ceph-crashcollector-estarhaohao-centos7-master02-547djvsw2 1/1 Running 0 3m18s
rook-ceph-crashcollector-estarhaohao-centos7-master03-787cdjq4b 1/1 Running 0 4m20s
rook-ceph-mgr-a-5bbf8f48d7-pdgkt 1/1 Running 0 3m51s
rook-ceph-mon-a-77d85f8944-56cgc 1/1 Running 0 5m59s
rook-ceph-mon-b-76d6564885-vxxhd 1/1 Running 0 5m30s
rook-ceph-mon-c-85858494c5-xjpf9 1/1 Running 0 4m7s
rook-ceph-operator-56496b9f8f-dblnq 1/1 Running 0 9m53s
rook-ceph-osd-0-5c4f45d76-n6qc6 1/1 Running 0 3m24s
rook-ceph-osd-1-7f7f575577-v7lg5 1/1 Running 0 3m21s
rook-ceph-osd-2-5677f9d654-wzzzq 1/1 Running 0 3m18s
rook-ceph-osd-prepare-estarhaohao-centos7-master01-fvxq9 0/1 Completed 0 3m47s
rook-ceph-osd-prepare-estarhaohao-centos7-master02-x7swq 0/1 Completed 0 3m46s
rook-ceph-osd-prepare-estarhaohao-centos7-master03-9vhfc 0/1 Completed 0 3m45s
rook-discover-2jp7z 1/1 Running 0 9m9s
rook-discover-hqq27 1/1 Running 0 9m9s
rook-discover-sx8c6 1/1 Running 0 9m9s
提示:若部署失败,master节点执行[root@k8smaster01 ceph]# kubectl delete -f ./
所有node节点执行如下清理操作:
rm -rf /var/lib/rook
/dev/mapper/ceph-*
dmsetup ls
dmsetup remove_all
dd if=/dev/zero of=/dev/sdb bs=512k count=1
wipefs -af /dev/sdb
2.6 部署Toolbox
toolbox是一个rook的工具集容器,该容器中的命令可以用来调试、测试Rook,对Ceph临时测试的操作一般在这个容器内执行。
[root@estarhaohao-centos7-master01 ceph]# kubectl apply -f toolbox.yaml
rook-ceph-tools-8574b74c5d-65x8r 1/1 Running 0 4s
2.7 测试rook-ceph
可以添加别名 就不用这样写这么多命令了
[root@estarhaohao-centos7-master01 ceph]# kubectl -n rook-ceph exec -it $(kubectl -n rook-ceph get pod -l "app=rook-ceph-tools" -o jsonpath='{.items[0].metadata.name}') --- ceph -s
cluster:
id: 2fb51620-1a29-4d64-9ad9-616e6435924a
health: HEALTH_OK
services:
mon: 3 daemons, quorum a,b,c (age 28m)
mgr: a(active, since 27m)
mds: myfs:1 {0=myfs-a=up:active} 1 up:standby-replay
osd: 3 osds: 3 up (since 27m), 3 in (since 27m)
data:
pools: 4 pools, 97 pgs
objects: 30 objects, 49 KiB
usage: 3.0 GiB used, 897 GiB / 900 GiB avail
pgs: 97 active+clean
io:
client: 852 B/s rd, 1 op/s rd, 0 op/s wr
[root@estarhaohao-centos7-master01 ~]# ceph osd tree
ID CLASS WEIGHT TYPE NAME STATUS REWEIGHT PRI-AFF
-1 0.87900 root default
-3 0.29300 host estarhaohao-centos7-master01
0 hdd 0.29300 osd.0 up 1.00000 1.00000
-7 0.29300 host estarhaohao-centos7-master02
2 hdd 0.29300 osd.2 up 1.00000 1.00000
-5 0.29300 host estarhaohao-centos7-master03
1 hdd 0.29300 osd.1 up 1.00000 1.00000
到这基本没什么问题了
三 Ceph 块存储
3.1 创建StorageClass
在提供(Provisioning)块存储之前,需要先创建StorageClass和存储池。K8S需要这两类资源,才能和Rook交互,进而分配持久卷(PV)。
解读:如下配置文件中会创建一个名为replicapool的存储池,和rook-ceph-block的storageClass。
[root@estarhaohao-centos7-master01 rbd]# pwd
/opt/rook/cluster/examples/kubernetes/ceph/csi/rbd
[root@estarhaohao-centos7-master01 rbd]# kubectl apply -f storageclass.yaml
[root@estarhaohao-centos7-master01 rbd]# kubectl get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
rook-ceph-block rook-ceph.rbd.csi.ceph.com Delete Immediate true 64m
3.2 测试rbd
[root@estarhaohao-centos7-master01 rbd]# kubectl get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
rook-ceph-block rook-ceph.rbd.csi.ceph.com Delete Immediate true 4s
[root@estarhaohao-centos7-master01 rbd]# kubectl apply -f pod.yaml
pod/csirbd-demo-pod created
[root@estarhaohao-centos7-master01 rbd]# kubectl apply -f pvc.yaml
persistentvolumeclaim/rbd-pvc created
[root@estarhaohao-centos7-master01 rbd]# kubectl get pvc rbd-pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
rbd-pvc Bound pvc-9f69bfab-a81b-41ea-93c7-59966661c867 1Gi RWO rook-ceph-block 5s
[root@estarhaohao-centos7-master01 rbd]# kubectl get pod csirbd-demo-pod
NAME READY STATUS RESTARTS AGE
csirbd-demo-pod 1/1 Running 0 70s
running状态基本没问题了
四 Ceph 文件存储
4.1 创建CephFilesystem
默认Ceph未部署对CephFS的支持,使用如下官方提供的默认yaml可部署文件存储的filesystem。
[root@estarhaohao-centos7-master01 ceph]# pwd
/opt/rook/cluster/examples/kubernetes/ceph
[root@estarhaohao-centos7-master01 ceph]# kubectl apply -f filesystem.yaml
[root@estarhaohao-centos7-master01 ceph]# kubectl get cephfilesystems.ceph.rook.io -n rook-ceph
NAME ACTIVEMDS AGE
myfs 1 55m
4.2 创建cephfs storageclass
使用如下官方提供的默认yaml可部署文件存储的StorageClass。
[root@estarhaohao-centos7-master01 cephfs]# pwd
/opt/rook/cluster/examples/kubernetes/ceph/csi/cephfs
[root@estarhaohao-centos7-master01 cephfs]# kubectl apply -f storageclass.yaml
[root@estarhaohao-centos7-master01 cephfs]# kubectl get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
rook-ceph-block rook-ceph.rbd.csi.ceph.com Delete Immediate true 70m
rook-cephfs rook-ceph.cephfs.csi.ceph.com Delete Immediate true 56m
4.3 测试cephfs
[root@estarhaohao-centos7-master01 cephfs]# kubectl apply -f pvc.yaml
[root@estarhaohao-centos7-master01 cephfs]# kubectl apply -f pod.yaml
[root@estarhaohao-centos7-master01 cephfs]# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
cephfs-pvc Bound pvc-e0d04036-a37c-4544-b71f-ac53f79c7832 1Gi RWO rook-cephfs 57m
[root@estarhaohao-centos7-master01 cephfs]# kubectl get pod
NAME READY STATUS RESTARTS AGE
csicephfs-demo-pod 1/1 Running 0 57m
cephfs基本没问题了
五 Ceph 对象存储
5.1 创建CephObjectStore
在提供(object)对象存储之前,需要先创建相应的支持,使用如下官方提供的默认yaml可部署对象存储的CephObjectStore。
[root@estarhaohao-centos7-master01 ceph]# pwd
/opt/rook/cluster/examples/kubernetes/ceph
[root@estarhaohao-centos7-master01 ceph]# kubectl apply -f object.yaml
[root@estarhaohao-centos7-master01 ceph]# kubectl get pod -n rook-ceph | grep rgw
rook-ceph-rgw-my-store-a-57dd44d5b-lkgfw 1/1 Running 0 2m51s
5.2 创建StorageClass
使用如下官方提供的默认yaml可部署对象存储的StorageClass。
[root@estarhaohao-centos7-master01 ceph]# kubectl apply -f storageclass-bucket-delete.yaml
storageclass.storage.k8s.io/rook-ceph-delete-bucket created
[root@estarhaohao-centos7-master01 ceph]# kubectl get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
rook-ceph-block rook-ceph.rbd.csi.ceph.com Delete Immediate true 85m
rook-ceph-delete-bucket rook-ceph.ceph.rook.io/bucket Delete Immediate false 5s
rook-cephfs rook-ceph.cephfs.csi.ceph.com Delete Immediate true 72m
5.3 创建bucket
使用如下官方提供的默认yaml可部署对象存储的bucket。
[root@k8smaster01 ceph]# kubectl create -f object-bucket-claim-delete.yaml
待定。。。。。
标签:centos7,rook,kubernetes,master01,ceph,root,estarhaohao 来源: https://www.cnblogs.com/estarhaohao/p/15973557.html