Kubernetes ceph-csi 环境搭建

1,563次阅读
没有评论

在kubernetes上搭建ceph csi环境
本文旨在说明如何在kubernetes集群中使用ceph-csi (版本 v2.0)做kubernetes的存储,官方的搭建的说明ceph-csi环境搭建
值得注意的是(官方的说明文档里面有):ceph-csi使用的是RBD的默认kernel模块,这个模块可能不支持所有的Ceph CRUSH或者RBD镜像的特征。

需要的环境
kubernetes (实验中使用的是1.15版本)
ceph 集群(实验中使用的是nautious版本)
ceph luminous集群也可以,但是要修改部分命令
搭建过程
创建一个ceph pool
[root@node1 ~]# ceph osd pool create kubernetes
[root@node1 ~]# rbd pool init kubernetes

编辑CEPH-CSI
为kubernetes和ceph-csi创建一个新的用户
[root@node1 ~]# ceph auth get-or-create client.kubernetes mon ‘profile rbd’ osd ‘profile rbd pool=kubernetes’ mgr ‘profile rbd pool=kubernetes’
[client.kubernetes]
key = AQD9o0Fd6hQRChAAt7fMaSZXduT3NWEqylNpmg==

注意:这里key后面对应的只是一个例子,实际配置中要以运行命令后产生的结果为准
这里的key使用user的key,后面配置中是需要用到的
如果是ceph luminous版本的集群,那么命令应该是ceph auth get-or-create client.kubernetes mon ‘allow r’ osd ‘allow rwx pool=kubernetes’ -o ceph.client.kubernetes.keyring
生成ceph-csi的kubernetes configmap
[root@node1 ~]# ceph mon dump
dumped monmap epoch 1
epoch 1
fsid 82e65362-72f7-4206-b94d-04e2c5e2d70d
last_changed 2020-05-29 05:26:42.313889
created 2020-05-29 05:26:42.313889
min_mon_release 14 (nautilus)
0: [v2:10.80.0.41:3300/0,v1:10.80.0.41:6789/0] mon.node1

注意,这里一共有两个需要使用的信息,第一个是fsid(可以称之为集群id),第二个是监控节点信息0: [v2:10.80.0.41:3300/0,v1:10.80.0.41:6789/0] mon.node1(可能有多个,实验中只配置了1个)
另外,目前的ceph-csi只支持V1版本的协议,所以监控节点那里我们只能用v1的那个IP和端口号
用以上的的信息生成configmap:

[root@node1 ~]# cat < csi-config-map.yaml

apiVersion: v1
kind: ConfigMap
data:
config.json: |-
[
{
“clusterID”: “82e65362-72f7-4206-b94d-04e2c5e2d70d”,
“monitors”: [
“10.80.0.41:6789”
]
}
]
metadata:
name: ceph-csi-config
EOF

在kubernetes集群上,将此configmap存储到集群
kubectl apply -f csi-config-map.yaml

生成ceph-csi cephx的secret

[root@node1 ~]# cat < csi-rbd-secret.yaml

apiVersion: v1
kind: Secret
metadata:
name: csi-rbd-secret
namespace: default
stringData:
userID: kubernetes
userKey: AQD9o0Fd6hQRChAAt7fMaSZXduT3NWEqylNpmg==
EOF

这里就用到了之前生成的用户的用户id(kubernetes)和key
将此配置存储到kubernetes中
kubectl apply -f csi-rbd-secret.yaml

配置ceph-csi插件(kubernetes上的rbac和提供存储功能的容器)
rbac部分
kubectl apply -f https://raw.githubusercontent.com/ceph/ceph-csi/master/deploy/rbd/kubernetes/csi-provisioner-rbac.yaml
kubectl apply -f https://raw.githubusercontent.com/ceph/ceph-csi/master/deploy/rbd/kubernetes/csi-nodeplugin-rbac.yaml

provisioner部分
$ wget https://raw.githubusercontent.com/ceph/ceph-csi/master/deploy/rbd/kubernetes/csi-rbdplugin-provisioner.yaml
$ kubectl apply -f csi-rbdplugin-provisioner.yaml
$ wget https://raw.githubusercontent.com/ceph/ceph-csi/master/deploy/rbd/kubernetes/csi-rbdplugin.yaml
$ kubectl apply -f csi-rbdplugin.yaml

这里的两个yaml文件默认都会去拉取镜像quay.io/cephcsi/cephcsi:canary,如果要是用其他版本,请自行修改yaml文件
使用ceph块儿设备
创建storageclass

$ cat < csi-rbd-sc.yaml

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: csi-rbd-sc
provisioner: rbd.csi.ceph.com
parameters:
clusterID: 82e65362-72f7-4206-b94d-04e2c5e2d70d
imageFeatures: layering
pool: kubernetes
csi.storage.k8s.io/provisioner-secret-name: csi-rbd-secret
csi.storage.k8s.io/provisioner-secret-namespace: default
csi.storage.k8s.io/node-stage-secret-name: csi-rbd-secret
csi.storage.k8s.io/node-stage-secret-namespace: default
reclaimPolicy: Delete
mountOptions:

  • discard
    EOF
    $ kubectl apply -f csi-rbd-sc.yaml

    第一,这里的clusterID对应之前的步骤中的fsid
    第二,这里新增了一项,imageFeatures,这个是用来确定创建的image的特征的,这个默认是用的rbd内核中的特征列表,但是我们用的linux内核不一定支持所有的特征

storageclass的yaml文件比较全的文件csi-ceph-sc.yaml

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: csi-rbd-sc
provisioner: rbd.csi.ceph.com
# If topology based provisioning is desired, delayed provisioning of
# PV is required and is enabled using the following attribute
# For further information read TODO
# volumeBindingMode: WaitForFirstConsumer
parameters:
# String representing a Ceph cluster to provision storage from.
# Should be unique across all Ceph clusters in use for provisioning,
# cannot be greater than 36 bytes in length, and should remain immutable for
# the lifetime of the StorageClass in use.
# Ensure to create an entry in the config map named ceph-csi-config, based on
# csi-config-map-sample.yaml, to accompany the string chosen to
# represent the Ceph cluster in clusterID below
clusterID:
# If you want to use erasure coded pool with RBD, you need to create
# two pools. one erasure coded and one replicated.
# You need to specify the replicated pool here in the pool parameter, it is
# used for the metadata of the images.
# The erasure coded pool must be set as the dataPool parameter below.
# dataPool: ec-data-pool
pool: rbd

 # RBD image features, CSI creates image with image-format 2
 # CSI RBD currently supports only `layering` feature.
 imageFeatures: layering

 # The secrets have to contain Ceph credentials with required access
 # to the 'pool'.
 csi.storage.k8s.io/provisioner-secret-name: csi-rbd-secret
 csi.storage.k8s.io/provisioner-secret-namespace: default
 csi.storage.k8s.io/controller-expand-secret-name: csi-rbd-secret
 csi.storage.k8s.io/controller-expand-secret-namespace: default
 csi.storage.k8s.io/node-stage-secret-name: csi-rbd-secret
 csi.storage.k8s.io/node-stage-secret-namespace: default
 # Specify the filesystem type of the volume. If not specified,
 # csi-provisioner will set default as `ext4`.
 csi.storage.k8s.io/fstype: ext4
 # uncomment the following to use rbd-nbd as mounter on supported nodes
 # mounter: rbd-nbd

 # Prefix to use for naming RBD images.
 # If omitted, defaults to "csi-vol-".
 # volumeNamePrefix: "foo-bar-"

 # Instruct the plugin it has to encrypt the volume
 # By default it is disabled. Valid values are "true" or "false".
 # A string is expected here, i.e. "true", not true.
 # encrypted: "true"

 # Use external key management system for encryption passphrases by specifying
 # a unique ID matching KMS ConfigMap. The ID is only used for correlation to
 # config map entry.
 # encryptionKMSID: <kms-config-id>

 # Add topology constrained pools configuration, if topology based pools
 # are setup, and topology constrained provisioning is required.
 # For further information read TODO<doc>
 # topologyConstrainedPools: |
 #   [{"poolName":"pool0",
 #     "dataPool":"ec-pool0" # optional, erasure-coded pool for data
 #     "domainSegments":[
 #       {"domainLabel":"region","value":"east"},
 #       {"domainLabel":"zone","value":"zone1"}]},
 #    {"poolName":"pool1",
 #     "dataPool":"ec-pool1" # optional, erasure-coded pool for data
 #     "domainSegments":[
 #       {"domainLabel":"region","value":"east"},
 #       {"domainLabel":"zone","value":"zone2"}]},
 #    {"poolName":"pool2",
 #     "dataPool":"ec-pool2" # optional, erasure-coded pool for data
 #     "domainSegments":[
 #       {"domainLabel":"region","value":"west"},
 #       {"domainLabel":"zone","value":"zone1"}]}
 #   ]

reclaimPolicy: Delete
allowVolumeExpansion: true
mountOptions:
– discard

这里有必要讲一下ceph的feature
实验所使用的ceph集群是基于centos7.5的,其linux内核版本为3.10,默认只支持ceph layering 特征
在没有指定imageFeature时,去申请pvc,会产生如下bug
Warning FailedMapVolume 0s (x4 over 5s) kubelet, k8s-1 MapVolume.SetUp failed for volume “pvc-5340f32e-fa2e-4f53-af1d-7154430af7a2” : rpc error: code = Internal desc = rbd: map failed exit status 6, rbd output: rbd: sysfs write failed
RBD image feature set mismatch. Try disabling features unsupported by the kernel with “rbd feature disable”.
In some cases useful info is found in syslog – try “dmesg | tail”.
rbd: map failed: (6) No such device or address

ceph nautious默认的image需要支持的特征有features: layering, exclusive-lock, object-map, fast-diff, deep-flatten; linux内核3.10版本只支持layering,所以这里有必要限制一下,当然我们也可以升级linux内核版本,不过这个代价就比较大了
创建PVC

$ cat < raw-block-pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: raw-block-pvc
spec:
accessModes:
– ReadWriteOnce
volumeMode: Block
resources:
requests:
storage: 1Gi
storageClassName: csi-rbd-sc
EOF
$ kubectl apply -f raw-block-pvc.yaml

创建使用PVC的Pod

$ cat < raw-block-pod.yaml

apiVersion: v1
kind: Pod
metadata:
name: pod-with-raw-block-volume
spec:
containers:
– name: fc-container
image: fedora:26
command: [“/bin/sh”, “-c”]
args: [“tail -f /dev/null”]
volumeDevices:
– name: data
devicePath: /dev/xvda
volumes:
– name: data
persistentVolumeClaim:
claimName: raw-block-pvc
EOF
$ kubectl apply -f raw-block-pod.yaml

基于Ceph filesystem的pvc和pod
pvc

$ cat < pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: rbd-pvc
spec:
accessModes:
– ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 1Gi
storageClassName: csi-rbd-sc
EOF
$ kubectl apply -f pvc.yaml

pod

$ cat < pod.yaml

apiVersion: v1
kind: Pod
metadata:
name: csi-rbd-demo-pod
spec:
containers:
– name: web-server
image: nginx
volumeMounts:
– name: mypvc
mountPath: /var/lib/www/html
volumes:
– name: mypvc
persistentVolumeClaim:
claimName: rbd-pvc
readOnly: false
EOF
$ kubectl apply -f pod.yaml

后续遇到的问题
ceph-csi 2.1 3.0版本部署时遇到的新问题
新版本的ceph-csi中需要一个ConfigMap,其名为ceph-csi-encryption-kms-config
解决方案:
找到需要用到它的yaml,注释掉所有相关引用
引用了该ConfigMap的yaml文件
deploy/rbd/kubernetes/csi-rbdplugin-provisioner.yaml
deploy/rbd/kubernetes/csi-rbdplugin.yaml
部署一个
样例路径ceph-csi/examples/kms/vault/kms-config.yaml
ceph-csi 使用过程中出现的”driver name rbd.csi.ceph.com not found in the list of registered CSI drivers”
遇到的问题描述
部署完成ceph-csi之后,携带的例子也跑通了,继续部署对master节点亲和性100%的pod,结果pod无法mount通过ceph-csi申请的PV
问题原因
ceph-csi官方的deploy目录下的daemonset的配置中,默认是不允许在master节点上部署pod的,这样导致,master节点上通过ceph-csi申请volume的pod,可以申请到PV但却无法挂载到pod
解决方案
在ceph-csi/deploy/rbd/kubernetes/csi-rbdplugin.yaml中的DaemonSet的spec中添加如下配置:
tolerations:

  • key: node-role.kubernetes.io/master
    effect: NoSchedule
正文完
可以使用微信扫码关注公众号(ID:xzluomor)
post-qrcode
 0
评论(没有评论)

文心AIGC

2023 年 12 月
 123
45678910
11121314151617
18192021222324
25262728293031
文心AIGC
文心AIGC
人工智能ChatGPT,AIGC指利用人工智能技术来生成内容,其中包括文字、语音、代码、图像、视频、机器人动作等等。被认为是继PGC、UGC之后的新型内容创作方式。AIGC作为元宇宙的新方向,近几年迭代速度呈现指数级爆发,谷歌、Meta、百度等平台型巨头持续布局
文章搜索
热门文章
潞晨尤洋:日常办公没必要上私有模型,这三类企业才需要 | MEET2026

潞晨尤洋:日常办公没必要上私有模型,这三类企业才需要 | MEET2026

潞晨尤洋:日常办公没必要上私有模型,这三类企业才需要 | MEET2026 Jay 2025-12-22 09...
面向「空天具身智能」,北航团队提出星座规划新基准丨NeurIPS’25

面向「空天具身智能」,北航团队提出星座规划新基准丨NeurIPS’25

面向「空天具身智能」,北航团队提出星座规划新基准丨NeurIPS’25 鹭羽 2025-12-13 22:37...
商汤Seko2.0重磅发布,合作短剧登顶抖音AI短剧榜No.1

商汤Seko2.0重磅发布,合作短剧登顶抖音AI短剧榜No.1

商汤Seko2.0重磅发布,合作短剧登顶抖音AI短剧榜No.1 十三 2025-12-15 14:13:14 ...
反超Nano Banana!OpenAI旗舰图像生成模型上线

反超Nano Banana!OpenAI旗舰图像生成模型上线

反超Nano Banana!OpenAI旗舰图像生成模型上线 Jay 2025-12-17 10:25:43 ...
OpenAI突然开源新模型!99.9%的权重是0,新稀疏性方法代替MoE

OpenAI突然开源新模型!99.9%的权重是0,新稀疏性方法代替MoE

OpenAI突然开源新模型!99.9%的权重是0,新稀疏性方法代替MoE 闻乐 2025-12-14 14:2...
最新评论
ufabet ufabet มีเกมให้เลือกเล่นมากมาย: เกมเดิมพันหลากหลาย ครบทุกค่ายดัง
tornado crypto mixer tornado crypto mixer Discover the power of privacy with TornadoCash! Learn how this decentralized mixer ensures your transactions remain confidential.
ดูบอลสด ดูบอลสด Very well presented. Every quote was awesome and thanks for sharing the content. Keep sharing and keep motivating others.
ดูบอลสด ดูบอลสด Pretty! This has been a really wonderful post. Many thanks for providing these details.
ดูบอลสด ดูบอลสด Pretty! This has been a really wonderful post. Many thanks for providing these details.
ดูบอลสด ดูบอลสด Hi there to all, for the reason that I am genuinely keen of reading this website’s post to be updated on a regular basis. It carries pleasant stuff.
Obrazy Sztuka Nowoczesna Obrazy Sztuka Nowoczesna Thank you for this wonderful contribution to the topic. Your ability to explain complex ideas simply is admirable.
ufabet ufabet Hi there to all, for the reason that I am genuinely keen of reading this website’s post to be updated on a regular basis. It carries pleasant stuff.
ufabet ufabet You’re so awesome! I don’t believe I have read a single thing like that before. So great to find someone with some original thoughts on this topic. Really.. thank you for starting this up. This website is something that is needed on the internet, someone with a little originality!
ufabet ufabet Very well presented. Every quote was awesome and thanks for sharing the content. Keep sharing and keep motivating others.
热评文章
交大高金朱宁:经济学家视角下AI时代的范式思维转变 | MEET2026

交大高金朱宁:经济学家视角下AI时代的范式思维转变 | MEET2026

交大高金朱宁:经济学家视角下AI时代的范式思维转变 | MEET2026 西风 2025-12-13 12:5...
半世纪难题48小时破解!陶哲轩组队把AI数学玩成打怪游戏了

半世纪难题48小时破解!陶哲轩组队把AI数学玩成打怪游戏了

半世纪难题48小时破解!陶哲轩组队把AI数学玩成打怪游戏了 鹭羽 2025-12-13 22:43:25 来源...
美国视频生成老炮儿,入局世界模型

美国视频生成老炮儿,入局世界模型

美国视频生成老炮儿,入局世界模型 鹭羽 2025-12-13 22:41:00 来源:量子位 三连发:真实场景...
面向「空天具身智能」,北航团队提出星座规划新基准丨NeurIPS’25

面向「空天具身智能」,北航团队提出星座规划新基准丨NeurIPS’25

面向「空天具身智能」,北航团队提出星座规划新基准丨NeurIPS’25 鹭羽 2025-12-13 22:37...
为Token付费是一件很愚蠢的事情,用户应该为智能付费丨RockAI刘凡平@MEET2026

为Token付费是一件很愚蠢的事情,用户应该为智能付费丨RockAI刘凡平@MEET2026

为Token付费是一件很愚蠢的事情,用户应该为智能付费丨RockAI刘凡平@MEET2026 西风 2025-...