kubernetes的ceph RBD volume(2): 使用Ceph RBD作为persistent volume

以下是使用ceph RBD作为persistent volume的例子:

A PersistentVolume (PV) is a piece of networked storage in the cluster that has been provisioned by an administrator. It is a resource in the cluster just like a node is a cluster resource. PVs are volume plugins like Volumes, but have a lifecycle independent of any individual pod that uses the PV. This API object captures the details of the implementation of the storage, be that NFS, iSCSI, or a cloud-provider-specific storage system.

A PersistentVolumeClaim (PVC) is a request for storage by a user. It is similar to a pod. Pods consume node resources and PVCs consume PV resources. Pods can request specific levels of resources (CPU and Memory). Claims can request specific size and access modes (e.g., can be mounted once read/write or many times read-only).

1. 先创建image在pool里。

2. 创建 PV

[root@testnew kube]# cat pv_ceph.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: ceph-pv
spec:
  capacity:
    storage: 50Gi
  accessModes:
    - ReadWriteOnce
  rbd:
    monitors:
     - 10.0.200.11:6789
     - 10.0.200.13:6789
     - 10.0.200.14:6789
    pool: kube
    image: vol2
    user: kube
    secretRef:
      name: ceph-secret
    fsType: ext4
    readOnly: false
  persistentVolumeReclaimPolicy: Recycle

kubectl create -f pv_ceph.yaml

[root@testnew kube]# kubectl get pv
NAME                                       CAPACITY   ACCESSMODES   RECLAIMPOLICY   STATUS    CLAIM                   REASON    AGE
ceph-pv                                    50Gi       RWO           Recycle         Bound     default/ceph-claim                4d
pvc-ac668f99-3b8b-11e7-8af9-fa163e01317b   20Gi       RWO           Delete          Bound     default/ceph-claim-sc             4d

3.  创建pvc

[root@testnew kube]# cat pvc_ceph.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: ceph-claim
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi

note: pvc和pv是一一对应的,所以storage在这设20G没用

kubectl create -f pvc_ceph.yaml

[root@testnew kube]# kubectl get pvc
NAME            STATUS    VOLUME                                     CAPACITY   ACCESSMODES   AGE
ceph-claim      Bound     ceph-pv                                    50Gi       RWO           4d

4. 创建pod

[root@testnew kube]# cat frontend-pvc-controller.yaml
apiVersion: v1
kind: ReplicationController
metadata:
  name: frontendpvc
  labels:
    name: frontendpvc
spec:
  replicas: 1
  selector:
    name: frontendpvc
  template:
    metadata:
      labels:
        name: frontendpvc
    spec:
      containers:
      - name: frontendpvc
        image: kubeguide/guestbook-php-frontend
        env:
        - name: GET_HOSTS_FROM
          value: env
        ports:
        - containerPort: 80
        volumeMounts:
        - mountPath: /mnt/rbd
          name: ceph-vol
      volumes:
      - name: ceph-vol
        persistentVolumeClaim:
          claimName: ceph-claim



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值