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 类型的存储卷时,需要指定要连接的目标服务器和认证信息等,这一点通常使用以下嵌套字段进行定义:

[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 集群,且上述配置示例中的部分参数需要参照实际环境进行修改。

posted @ 2022-06-24 10:05  左扬  阅读(362)  评论(0编辑  收藏  举报
levels of contents