Kubernetes实战(三十一)-使用开源CEPH作为后端StorageClass

本文主要是介绍Kubernetes实战(三十一)-使用开源CEPH作为后端StorageClass,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1 引言

K8S在1.13版本开始支持使用Ceph作为StorageClass。其中云原生存储Rook和开源Ceph应用都非常广泛。本文主要介绍K8S如何对接开源Ceph使用RBD卷。

K8S对接Ceph的技术栈如下图所示。K8S主要通过容器存储接口CSI和Ceph进行交互。

Ceph官方文档:Block Devices and Kubernetes — Ceph Documentation

CSI的官方地址:GitHub - ceph/ceph-csi at release-v3.9 

在部署CSI前需要确认好部署的CSI版本,在CSI的官网,可以看到CSI版本与K8S之间的对应关系。

CSI与Ceph之间的对应关系参考:GitHub - ceph/ceph-csi: CSI driver for Ceph 

作者环境的K8S版本为1.24,Ceph版本为14,因此使用3.5.1版本的CSI。以下是部署过程。

2 Ceph侧资源创建

[root@ceph-1 ~]# ceph osd pool create k8s 64 64  ##创建k8s存储池
pool 'k8s' created
[root@ceph-1 ~]# ceph auth get-or-create client.k8s mon 'profile rbd' osd 'profile rbd pool=k8s' mgr 'profile rbd pool=k8s'  ##新建一个ceph用户,用户名和key后续需要使用到
[client.k8s]key = AQBClIVj8usBLxAAxTl0DwZCz9prNRRRI9Bl5A==
[root@ceph-1 ~]# ceph -s |grep id  ##查看ceph 的fsidid:     395b7a30-eb33-460d-8e38-524fc48c58cb
[root@ceph-1 ~]# ceph mon stat  #查看ceph的mon服务ip,我们主要采用v1版本的ip和端口
e3: 3 mons at {
ceph-1=[v2:10.0.245.192:3300/0,v1:10.0.245.192:6789/0],
ceph-2=[v2:10.0.138.175:3300/0,v1:10.0.138.175:6789/0],
ceph-3=[v2:10.0.28.226:3300/0,v1:10.0.28.226:6789/0]}, 
election epoch 1112, leader 0 ceph-1, quorum 0,1,2 ceph-1,ceph-2,ceph-3        

3 ceph-csi部署环境准备

主要步骤为下载官方csi部署文件,创建csi需要使用到的configmap及sa、secret。使用到的文件均位于ceph-csi/deploy/rbd/kubernetes/ 目录下,同时会新建以下三个文件用于保存ceph相关配置

  • csi-kms-config-map.yaml
  • ceph-config-map.yaml
  • csi-rbd-secret.yaml
[root@k8s-master02 ~]# wget https://github.com/ceph/ceph-csi/archive/refs/tags/v3.5.1.tar.gz ##本次实验ceph版本为14,使用3.5.1版本有较好的兼容性
[root@k8s-master02 ~]# tar xvf v3.5.1.tar.gz
[root@k8s-master02 ~]# mv ceph-csi-3.5.1 ceph-csi
[root@k8s-master02 ~]# cd /root/ceph-csi/deploy/rbd/kubernetes/
[root@k8s-master02 kubernetes]# cat csi-config-map.yaml ##编辑config-map文件
#
# /!\ DO NOT MODIFY THIS FILE
#
# This file has been automatically generated by Ceph-CSI yamlgen.
# The source for the contents can be found in the api/deploy directory, make
# your modifications there.
#
---
apiVersion: v1
kind: ConfigMap
metadata:name: "ceph-csi-config"
data:config.json: |-[{"clusterID": "395b7a30-eb33-460d-8e38-524fc48c58cb",  #ceph -s输出的id"monitors": ["10.0.245.192:6789",  ##三个mon服务的ip地址"10.0.138.175:6789","10.0.28.226:6789"]}]
[root@k8s-master02 kubernetes]# kubectl create ns ceph-csi  ##创建namespace
namespace/ceph-csi created
[root@k8s-master02 kubernetes]# kubectl -n ceph-csi create -f csi-config-map.yaml 
configmap/ceph-csi-config created
[root@k8s-master02 kubernetes]# cat csi-kms-config-map.yaml ##新建kms-config文件
---
apiVersion: v1
kind: ConfigMap
data:config.json: |-{}
metadata:name: ceph-csi-encryption-kms-config
[root@k8s-master02 kubernetes]# kubectl create -n ceph-csi -f csi-kms-config-map.yaml 
configmap/ceph-csi-encryption-kms-config created
[root@k8s-master02 kubernetes]# cat ceph-config-map.yaml ##新建一个ceph-config文件,ceph.conf中的内容与ceph集群中/etc/ceph/ceph.conf的内容保持一致
---
apiVersion: v1
kind: ConfigMap
data:ceph.conf: |[global]fsid = 395b7a30-eb33-460d-8e38-524fc48c58cbpublic_network = 10.0.0.0/16cluster_network = 10.0.0.0/16mon_initial_members = ceph-1mon_host = 10.0.245.192auth_cluster_required = cephxauth_service_required = cephxauth_client_required = cephxmon_allow_pool_delete = trueauth_allow_insecure_global_id_reclaim = falserbd_default_format = 2# keyring is a required key and its value should be emptykeyring: |
metadata:name: ceph-config
[root@k8s-master02 kubernetes]# kubectl -n ceph-csi create -f ceph-config-map.yaml 
configmap/ceph-config created
[root@k8s-master02 kubernetes]# cat csi-rbd-secret.yaml ##新建一个secret文件
apiVersion: v1
kind: Secret
metadata:name: csi-rbd-secretnamespace: ceph-csi
stringData:userID: k8s   ##ceph集群上创建额用户userKey: AQBClIVj8usBLxAAxTl0DwZCz9prNRRRI9Bl5A==  ##用户的key
[root@k8s-master02 kubernetes]# kubectl create -f csi-rbd-secret.yaml 
secret/csi-rbd-secret created  
[root@k8s-master02 ~]# sed -i "s/namespace: default/namespace: ceph-csi/g"  $(grep -rl "namespace: default" ./)  #将所有yaml文件的namespace从default改成ceph-csi
[root@k8s-master02 kubernetes]# cat csi-provisioner-rbac.yaml ##检查配置文件中namespace是否更改成功
---
apiVersion: v1
kind: ServiceAccount
metadata:name: rbd-csi-provisioner# replace with non-default namespace namenamespace: ceph-csi ---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:name: rbd-external-provisioner-runner##创建rbac权限
[root@k8s-master02 kubernetes]# kubectl create -f csi-provisioner-rbac.yaml 
serviceaccount/rbd-csi-provisioner created
clusterrole.rbac.authorization.k8s.io/rbd-external-provisioner-runner created
clusterrolebinding.rbac.authorization.k8s.io/rbd-csi-provisioner-role created
role.rbac.authorization.k8s.io/rbd-external-provisioner-cfg created
rolebinding.rbac.authorization.k8s.io/rbd-csi-provisioner-role-cfg created
[root@k8s-master02 kubernetes]# kubectl create -f csi-nodeplugin-rbac.yaml 
serviceaccount/rbd-csi-nodeplugin created
clusterrole.rbac.authorization.k8s.io/rbd-csi-nodeplugin created
clusterrolebinding.rbac.authorization.k8s.io/rbd-csi-nodeplugin created

4 部署ceph-csi相关容器

yaml中的镜像源需要替换,否则部署时镜像可能下载不成功。如果部署其他版本的csi,可以自己设置通过阿里云容器镜像服务托管下载http://k8s.gcr.io中相关csi版本的镜像。

[root@k8s-master02 kubernetes]# sed -i 's#k8s.gcr.io/sig-storage/#registry.cn-shanghai.aliyuncs.com/singless/#' csi-rbdplugin*  ##替换yaml里的镜像源
[root@k8s-master02 kubernetes]# kubectl -n ceph-csi create -f csi-rbdplugin-provisioner.yaml ##部署sidecar容器,yaml文件里的所有镜像地址修改为registry.cn-shanghai.aliyuncs.com/singless/
service/csi-rbdplugin-provisioner created
deployment.apps/csi-rbdplugin-provisioner created
[root@k8s-master02 kubernetes]# kubectl -n ceph-csi create -f csi-rbdplugin.yaml ##部署RBD CSI driver容器
daemonset.apps/csi-rbdplugin created
service/csi-metrics-rbdplugin created
[root@k8s-master02 kubernetes]# kubectl get pod -n ceph-csi  ##检查pod是否都已启动
NAME                                         READY   STATUS    RESTARTS   AGE
csi-rbdplugin-8s6cf                          3/3     Running   0          60m
csi-rbdplugin-g74qd                          3/3     Running   0          60m
csi-rbdplugin-provisioner-56d6d755c7-jhcwl   7/7     Running   0          14m
csi-rbdplugin-provisioner-56d6d755c7-lz2zf   7/7     Running   0          14m
csi-rbdplugin-provisioner-56d6d755c7-pxw7q   7/7     Running   0          14m
csi-rbdplugin-twjdh                          3/3     Running   0          60m
csi-rbdplugin-v529x                          3/3     Running   0          60m
csi-rbdplugin-wgh5c                          3/3     Running   0          60m

5 创建StorageClass

[root@k8s-master02 kubernetes]# cat storageclass.yaml 
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:name: csi-rbd-sc
provisioner: rbd.csi.ceph.com
parameters:clusterID: 395b7a30-eb33-460d-8e38-524fc48c58cb  ##ceph集群IDpool: k8s   ##ceph集群的pool名imageFeatures: layering  ##定义创建的rbd featurescsi.storage.k8s.io/provisioner-secret-name: csi-rbd-secretcsi.storage.k8s.io/provisioner-secret-namespace: ceph-csicsi.storage.k8s.io/controller-expand-secret-name: csi-rbd-secretcsi.storage.k8s.io/controller-expand-secret-namespace: ceph-csicsi.storage.k8s.io/node-stage-secret-name: csi-rbd-secretcsi.storage.k8s.io/node-stage-secret-namespace: ceph-csicsi.storage.k8s/fstype: ext4
reclaimPolicy: Delete
allowVolumeExpansion: true
mountOptions:- discard
[root@k8s-master02 kubernetes]# kubectl create -f storageclass.yaml 
storageclass.storage.k8s.io/csi-rbd-sc created

6 创建PV

[root@k8s-master02 kubernetes]# cd /root/ceph-csi/examples/rbd/
[root@k8s-master02 rbd]# kubectl create -f pvc.yaml 
persistentvolumeclaim/rbd-pvc created

本文主要介绍K8S对接Ceph使用RBD块的方法,对象存储或文件存储可以参考官方文档进行对接。

这篇关于Kubernetes实战(三十一)-使用开源CEPH作为后端StorageClass的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/828485

相关文章

Python使用Tenacity一行代码实现自动重试详解

《Python使用Tenacity一行代码实现自动重试详解》tenacity是一个专为Python设计的通用重试库,它的核心理念就是用简单、清晰的方式,为任何可能失败的操作添加重试能力,下面我们就来看... 目录一切始于一个简单的 API 调用Tenacity 入门:一行代码实现优雅重试精细控制:让重试按我

MySQL中EXISTS与IN用法使用与对比分析

《MySQL中EXISTS与IN用法使用与对比分析》在MySQL中,EXISTS和IN都用于子查询中根据另一个查询的结果来过滤主查询的记录,本文将基于工作原理、效率和应用场景进行全面对比... 目录一、基本用法详解1. IN 运算符2. EXISTS 运算符二、EXISTS 与 IN 的选择策略三、性能对比

使用Python构建智能BAT文件生成器的完美解决方案

《使用Python构建智能BAT文件生成器的完美解决方案》这篇文章主要为大家详细介绍了如何使用wxPython构建一个智能的BAT文件生成器,它不仅能够为Python脚本生成启动脚本,还提供了完整的文... 目录引言运行效果图项目背景与需求分析核心需求技术选型核心功能实现1. 数据库设计2. 界面布局设计3

SQL Server跟踪自动统计信息更新实战指南

《SQLServer跟踪自动统计信息更新实战指南》本文详解SQLServer自动统计信息更新的跟踪方法,推荐使用扩展事件实时捕获更新操作及详细信息,同时结合系统视图快速检查统计信息状态,重点强调修... 目录SQL Server 如何跟踪自动统计信息更新:深入解析与实战指南 核心跟踪方法1️⃣ 利用系统目录

使用IDEA部署Docker应用指南分享

《使用IDEA部署Docker应用指南分享》本文介绍了使用IDEA部署Docker应用的四步流程:创建Dockerfile、配置IDEADocker连接、设置运行调试环境、构建运行镜像,并强调需准备本... 目录一、创建 dockerfile 配置文件二、配置 IDEA 的 Docker 连接三、配置 Do

Android Paging 分页加载库使用实践

《AndroidPaging分页加载库使用实践》AndroidPaging库是Jetpack组件的一部分,它提供了一套完整的解决方案来处理大型数据集的分页加载,本文将深入探讨Paging库... 目录前言一、Paging 库概述二、Paging 3 核心组件1. PagingSource2. Pager3.

java中pdf模版填充表单踩坑实战记录(itextPdf、openPdf、pdfbox)

《java中pdf模版填充表单踩坑实战记录(itextPdf、openPdf、pdfbox)》:本文主要介绍java中pdf模版填充表单踩坑的相关资料,OpenPDF、iText、PDFBox是三... 目录准备Pdf模版方法1:itextpdf7填充表单(1)加入依赖(2)代码(3)遇到的问题方法2:pd

python使用try函数详解

《python使用try函数详解》Pythontry语句用于异常处理,支持捕获特定/多种异常、else/final子句确保资源释放,结合with语句自动清理,可自定义异常及嵌套结构,灵活应对错误场景... 目录try 函数的基本语法捕获特定异常捕获多个异常使用 else 子句使用 finally 子句捕获所

C++11右值引用与Lambda表达式的使用

《C++11右值引用与Lambda表达式的使用》C++11引入右值引用,实现移动语义提升性能,支持资源转移与完美转发;同时引入Lambda表达式,简化匿名函数定义,通过捕获列表和参数列表灵活处理变量... 目录C++11新特性右值引用和移动语义左值 / 右值常见的左值和右值移动语义移动构造函数移动复制运算符

Python对接支付宝支付之使用AliPay实现的详细操作指南

《Python对接支付宝支付之使用AliPay实现的详细操作指南》支付宝没有提供PythonSDK,但是强大的github就有提供python-alipay-sdk,封装里很多复杂操作,使用这个我们就... 目录一、引言二、准备工作2.1 支付宝开放平台入驻与应用创建2.2 密钥生成与配置2.3 安装ali