四、K8s连接Ceph

我们主要通过ceph-csi进行kK8s集群和ceph rbd的连接。

获取Ceph-CSI

git clone https://github.com/ceph/ceph-csi.git
cd ceph-csi/deploy/rbd/kubernetes

修改文件

  • 修改csi-rbdplugin-provisioner.yaml和csi-rbdplugin.yaml文件

将csi-rbdplugin-provisioner.yaml和csi-rbdplugin.yaml文件中ceph-csi-encryption-kms-config配置注释掉

#- name: ceph-csi-encryption-kms-config
# mountPath: /etc/ceph-csi-encryption-kms-config/
#- name: ceph-csi-encryption-kms-config
# configMap:
# name: ceph-csi-encryption-kms-config

配置csi-config-map.yaml文件中ceph集群的信息

---
apiVersion: v1
kind: ConfigMap
data:
  config.json: |-
    [
      {
        "clusterID": "ec15eb3e-eb66-4431-acda-428e91658560",    // 通过ceph集群的ID
        "monitors": [
          "192.168.2.90:6789"
        ]
      }
    ]
metadata:
  name: ceph-csi-config

config-map.yaml

csi-rbdplugin-provisioner.yaml和csi-rbdplugin.yaml里面用到了ConfigMap ceph-config该文件在example文件夹中,也可以自己创建

apiVersion: v1
kind: ConfigMap
data:
  ceph.conf: |
    [global]
    auth_cluster_required = cephx
    auth_service_required = cephx
    auth_client_required = cephx

  # keyring is a required key and its value should be empty
  keyring: |
metadata:
  name: ceph-config

修改下载镜像地址

csi-rbdplugin.yamlcsi-rbdplugin-provisioner.yaml中的镜像地址是google的需要修改,我这里部署的时候修改成了阿里云和对应的地址

  registry.aliyuncs.com/google_containers/csi-node-driver-registrar:v2.5.1
  quay.io/cephcsi/cephcsi:canary
  gcr.lank8s.cn/k8s-staging-sig-storage/csi-provisioner:canary
  registry.aliyuncs.com/google_containers/csi-snapshotter:v6.0.1
  registry.aliyuncs.com/google_containers/csi-attacher:v3.4.0
  registry.aliyuncs.com/google_containers/csi-resizer:v1.4.0

部署csi

kubectl apply -f kubernetes/
kubectl get pods
csi-rbdplugin-ms5lk                          3/3     Running   0          7h12m
csi-rbdplugin-provisioner-597875dbb4-l49ht   7/7     Running   0          7h12m
csi-rbdplugin-rz8px                          3/3     Running   0          7h12m
csi-rbdplugin-shjb8                          3/3     Running   0          7h12m
nfs-client-provisioner-8cbf68bfd-ptzz2       1/1     Running   2          3d10h

Ceph服务器创建存储池

#创建pool
ceph osd pool create rbddata 8 8
rbd pool init rbddata
# 获取admin密钥
ceph auth get-key client.admin

创建SC

创建ceph密钥

---
apiVersion: v1
kind: Secret
metadata:
  name: csi-rbd-secret
  namespace: default
stringData:
  userID: kubernetes
  userKey: AQCOp6ZiP42IBBAA4J+Eeg7/oGflMMkDN15XYw==
  encryptionPassphrase: test_passphrase

创建storageclass

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: csi-rbd-sc
  namespace: default
  annotations:
    storageclass.kubernetes.io/is-default-class: "true"
provisioner: rbd.csi.ceph.com
parameters:
  clusterID: ec15eb3e-eb66-4431-acda-428e91658560
  # monitors: 192.168.2.90:6789
  pool: rbddata
  # imageFormat: "2"
  imageFeatures: "layering"
  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
  csi.storage.k8s.io/fstype: ext4
reclaimPolicy: Delete
allowVolumeExpansion: true
mountOptions:
   - discard

部署

kubectl apply -f ceph-secret.yaml
kubectl apply -f storageclass.yaml

测试

创建pvc

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: rbd-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  storageClassName: csi-rbd-sc
kubectl apply -f pvc.yaml
kubectl get pvc rbd-pvc
NAME      STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
rbd-pvc   Bound    pvc-11b931b0-7cb5-40e1-815b-c15659310593   1Gi      RWO            csi-rbd-sc        0

POD

---
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
kubectl apply -f pod.yaml
kubectl get pods csi-rbd-demo-pod
NAME               READY   STATUS    RESTARTS   AGE
csi-rbd-demo-pod   1/1     Running   0          0

kubectl exec -ti csi-rbd-demo-pod -- bash
df -h
Filesystem               Size  Used Avail Use% Mounted on
overlay                  199G  7.4G  192G   4% /
tmpfs                     64M     0   64M   0% /dev
tmpfs                    7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/centos-root  199G  7.4G  192G   4% /etc/hosts
shm                       64M     0   64M   0% /dev/shm
/dev/rbd0                976M  2.6M  958M   1% /var/lib/www/html
tmpfs                    7.8G   12K  7.8G   1% /run/secrets/kubernetes.io/serviceaccount
tmpfs                    7.8G     0  7.8G   0% /proc/acpi
tmpfs                    7.8G     0  7.8G   0% /proc/scsi
tmpfs                    7.8G     0  7.8G   0% /sys/firmware
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

苜蓿花乐园

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值