Kubernetes——RBD存储卷
RBD存储卷
Ceph 是一个专注于分布式的、弹性可扩展的、高可靠的、性能优异的存储系统平台,同时支持提供块设备、文件系统和 REST 三种存储接口。它是一个高度可配置的系统,并提供了一个命令行界面用于监视和控制其存储集群。Ceph 还包含鉴证和授权功能,可兼容多种存储网关接口,如 OpenStack Swift 和 Amazon S3。
Kubernetes 也支持通过 RBD 卷类型使用 Ceph 存储系统为 Pod 提供存储卷。要配置 Pod 资源使用 RBD 存储卷,需要事先满足以下几个前提条件:
- 存在某可用的 Ceph RBD 存储集群,否则就需要创建一个。
- 在 Ceph RBD 集群中创建一个能满足 Pod 资源存储需要的存镜像(image)。
- 在 Kubernetes 集群内的各节点上安装 Ceph 客户端程序包(ceph-common)。
在配置 RBD 类型的存储卷时,需要指定要连接的目标服务器和认证信息等,这一点通常使用以下嵌套字段进行定义:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | [root@mh-k8s-master-247-10 ~] # kubectl explain pod.spec.volumes.rbd KIND: Pod VERSION: v1 RESOURCE: rbd <Object> DESCRIPTION: RBD represents a Rados Block Device mount on the host that shares a pod's lifetime. More info: https: //examples .k8s.io /volumes/rbd/README .md Represents a Rados Block Device mount that lasts the lifetime of a pod. RBD volumes support ownership management and SELinux relabeling. FIELDS: fsType <string> Filesystem type of the volume that you want to mount . Tip: Ensure that the filesystem type is supported by the host operating system. Examples: "ext4" , "xfs" , "ntfs" . Implicitly inferred to be "ext4" if unspecified. More info: https: //kubernetes .io /docs/concepts/storage/volumes #rbd image <string> -required- The rados image name. More info: https: //examples .k8s.io /volumes/rbd/README .md #how-to-use-it keyring <string> Keyring is the path to key ring for RBDUser. Default is /etc/ceph/keyring . More info: https: //examples .k8s.io /volumes/rbd/README .md #how-to-use-it monitors <[]string> -required- A collection of Ceph monitors. More info: https: //examples .k8s.io /volumes/rbd/README .md #how-to-use-it pool <string> The rados pool name. Default is rbd. More info: https: //examples .k8s.io /volumes/rbd/README .md #how-to-use-it readOnly <boolean> ReadOnly here will force the ReadOnly setting in VolumeMounts. Defaults to false . More info: https: //examples .k8s.io /volumes/rbd/README .md #how-to-use-it secretRef <Object> SecretRef is name of the authentication secret for RBDUser. If provided overrides keyring. Default is nil. More info: https: //examples .k8s.io /volumes/rbd/README .md #how-to-use-it user <string> The rados user name. Default is admin. More info: https: //examples .k8s.io /volumes/rbd/README .md #how-to-use-it [root@mh-k8s-master-247-10 ~] # |
常用字段如下:
-
- monitors <[]string> -required-: Ceph 存储监视器,逗号分隔的字符串列表,必选字段。
- image <string> -required-: rados image 的名称,必选字段。
- pool <string>: rados 存储名称,默认为 RBD。
- user <user>: rados 用户名,默认为 admin。
- keyring <string>: RBD 用户认证时使用的 keyring 文件路径,默认为 /etc/ceph/keyring。
- secretRef <Object>: RBD 用户认证时使用的保存有相应认证信息的 Secret 对象,会覆盖由 keyring 字段提供的密钥信息。
- readOnly <boolean>: 是否以只读的方式进行访问。
- fsType: 要挂载的存储卷的文件系统类型,至少应该是节点操作系统支持的文件系统,如 ext4、xfs、ntfs 等,默认为 ext4。
下面是一个定义在 vo-rbd.yaml 配置文件中使用 RBD 存储卷的 Pod 资源示例:
apiVersion v1
kind: Pod
metadata:
name: vol-rbd-pod
spec:
containers:
- name: redis
image: redis:4-alpine
ports:
- containerPort: 6379
name: redisport
volumeMounts:
- mountPath: /data
name: reids-rdb-vol
volumes:
- name: redis-rbd-vol
rbd:
monitors:
- '10.255.243.56':6789
- '10.255.243.57':6789
- '10.255.243.58':6789
pool: kube
image: redis
fsType: ext4
readOnly: false
user: admin
secretRef:
name:ceph-secret
此示例依赖于事先存在的一个 Ceph 存储集群,这里假设其监视器的地址为 10.255.243.56、10.255.243.57、10.255.243.58 三个主机 IP,并且集群上的存储池 kube 中存在创建好的 image Redis,此image 拥有 ext4 文件系统。
Ceph 客户端访问集群时需要事先完成认证之后才能进行后续的访问操作,上面的示例中,其认证信息保存于名为 ceph-secret 的 Secret 资源对象中。
上面示例的依赖于一个可用的 Ceph 集群,且上述配置示例中的部分参数需要参照实际环境进行修改。
分类:
Kubernetes专题精讲
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2018-06-24 《SaltStack技术入门与实践》—— Job管理
2018-06-24 【SaltStack官方版】—— job management
2018-06-24 《SaltStack技术入门与实践》——执行结果处理
2018-06-24 【SaltStack官方版】—— returners——返回器
2018-06-24 【SaltStack官方版】—— states教程, part 5 - 用SALT编排
2018-06-24 【SaltStack官方版】—— states教程, part 4 - states 说明