伍佰目录 短网址
  当前位置:海洋目录网 » 站长资讯 » 站长资讯 » 文章详细 订阅RssFeed

kubernetes存储之ceph-csi

来源:本站原创 浏览:104次 时间:2022-08-10
kubernetes存储之ceph-csi

scofield 菜鸟运维杂谈

0、前提

因为kubernetes默认的provisioner: kubernetes.io/rbd 无法正常使用,改用ceph官网提供的provisioner: rbd.csi.ceph.com,需要部署相关的csi插件以及配置ceph连接授权,所以本文记录如下。

1、下载部署清单
git clone https://github.com/ceph/ceph-csi.gitcd ceph-csi/deploy/rbd/kubernetes[root@qd01-stop-k8s-master001 kubernetes]# ls -ltotal 36-rw-r--r-- 1 root root  304 Feb 23 16:24 csi-config-map.yaml-rw-r--r-- 1 root root 1674 Feb 23 16:20 csi-nodeplugin-psp.yaml-rw-r--r-- 1 root root  747 Feb 23 16:20 csi-nodeplugin-rbac.yaml-rw-r--r-- 1 root root 1300 Feb 23 16:20 csi-provisioner-psp.yaml-rw-r--r-- 1 root root 2915 Feb 23 16:20 csi-provisioner-rbac.yaml-rw-r--r-- 1 root root 7123 Feb 23 16:34 csi-rbdplugin-provisioner.yaml-rw-r--r-- 1 root root 5841 Feb 23 16:34 csi-rbdplugin.yaml

如下是需要的镜像

k8s.gcr.io/sig-storage/csi-provisioner:v2.0.4k8s.gcr.io/sig-storage/csi-snapshotter:v3.0.2k8s.gcr.io/sig-storage/csi-attacher:v3.0.2k8s.gcr.io/sig-storage/csi-resizer:v1.0.1k8s.gcr.io/sig-storage/csi-node-driver-registrar:v2.0.1quay.io/cephcsi/cephcsi:canary如果您的网络不能从k8s.gcr.io下载镜像,可以改成如下scofield/csi-provisioner:v2.0.4scofield/csi-snapshotter:v3.0.2scofield/csi-attacher:v3.0.2scofield/csi-resizer:v1.0.1scofield/csi-node-driver-registrar:v2.0.1scofield/cephcsi:canary
2、修改配置

将kms所在行注释掉,因为没有这个配置,否则会部署失败

root@qd01-stop-k8s-master001 kubernetes]# vim csi-rbdplugin-provisioner.yaml[root@qd01-stop-k8s-master001 kubernetes]# vim csi-rbdplugin.yaml        #- 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
3、执行部署
[root@qd01-stop-k8s-master001 kubernetes]# kubectl apply -f . -n csiconfigmap/ceph-csi-config createdpodsecuritypolicy.policy/rbd-csi-nodeplugin-psp createdrole.rbac.authorization.k8s.io/rbd-csi-nodeplugin-psp createdrolebinding.rbac.authorization.k8s.io/rbd-csi-nodeplugin-psp createdserviceaccount/rbd-csi-nodeplugin createdclusterrole.rbac.authorization.k8s.io/rbd-csi-nodeplugin createdclusterrolebinding.rbac.authorization.k8s.io/rbd-csi-nodeplugin createdpodsecuritypolicy.policy/rbd-csi-provisioner-psp createdrole.rbac.authorization.k8s.io/rbd-csi-provisioner-psp createdrolebinding.rbac.authorization.k8s.io/rbd-csi-provisioner-psp createdserviceaccount/rbd-csi-provisioner createdclusterrole.rbac.authorization.k8s.io/rbd-external-provisioner-runner createdclusterrolebinding.rbac.authorization.k8s.io/rbd-csi-provisioner-role createdrole.rbac.authorization.k8s.io/rbd-external-provisioner-cfg createdrolebinding.rbac.authorization.k8s.io/rbd-csi-provisioner-role-cfg createdservice/csi-rbdplugin-provisioner createddeployment.apps/csi-rbdplugin-provisioner createddaemonset.apps/csi-rbdplugin createdservice/csi-metrics-rbdplugin created等待部署完成即可[root@qd01-stop-k8s-master001 UseRBD]# kubectl get po -n csiNAME                                        READY   STATUS    RESTARTS   AGEcsi-rbdplugin-5xtbz                         3/3     Running   0          29mcsi-rbdplugin-hwrsr                         3/3     Running   0          29mcsi-rbdplugin-mtscj                         3/3     Running   0          29mcsi-rbdplugin-pmqjv                         3/3     Running   0          29mcsi-rbdplugin-provisioner-b96dc4989-fd7kt   7/7     Running   0          29mcsi-rbdplugin-provisioner-b96dc4989-tk9bv   7/7     Running   0          29mcsi-rbdplugin-provisioner-b96dc4989-xrxgz   7/7     Running   0          29mcsi-rbdplugin-qzsjr                         3/3     Running   0          29mcsi-rbdplugin-tt4b9                         3/3     Running   0          29mcsi-rbdplugin-w429q                         3/3     Running   0          29mcsi-rbdplugin-w6xp7                         3/3     Running   0          29mcsi-rbdplugin-wxc94                         3/3     Running   0          29m
4、使用ceph -rbd

1、创建需要的secret
创建csi-rbd-secret.yaml

---apiVersion: v1kind: Secretmetadata:  name: csi-rbd-secret  namespace: csistringData:  userID: admin  userKey: AQALpatf81ZmNhAAz6xt03v4boTYj7o5MOa0iQ==[root@qd01-stop-k8s-master001 UseRBD]# kubectl apply -f csi-rbd-secret.yamlsecret/csi-rbd-secret created

2、创建存储类sc
创建storageclass.yaml

---apiVersion: storage.k8s.io/v1kind: StorageClassmetadata:   name: rbdprovisioner: rbd.csi.ceph.comparameters:   clusterID: ec7ee19a-f7c6-4ed0-93a7-f48af473352c   pool: k8s   imageFeatures: layering   csi.storage.k8s.io/provisioner-secret-name: csi-rbd-secret   csi.storage.k8s.io/provisioner-secret-namespace: csi   csi.storage.k8s.io/controller-expand-secret-name: csi-rbd-secret   csi.storage.k8s.io/controller-expand-secret-namespace: csi   csi.storage.k8s.io/node-stage-secret-name: csi-rbd-secret   csi.storage.k8s.io/node-stage-secret-namespace: csi   csi.storage.k8s.io/fstype: xfsreclaimPolicy: DeleteallowVolumeExpansion: truemountOptions:   - discard[root@qd01-stop-k8s-master001 UseRBD]# kubectl apply -f storageclass.yamlstorageclass.storage.k8s.io/rbd created[root@qd01-stop-k8s-master001 UseRBD]# kubectl get scNAME   PROVISIONER        RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGErbd    rbd.csi.ceph.com   Delete          Immediate           true                   20m

3、创建PVC验证sc是否可用
创建raw-block-pvc.yaml

---apiVersion: v1kind: PersistentVolumeClaimmetadata:  name: raw-block-pvcspec:  accessModes:    - ReadWriteOnce  volumeMode: Block  resources:    requests:      storage: 1Gi  storageClassName: rbd[root@qd01-stop-k8s-master001 UseRBD]# kubectl apply -f raw-block-pvc.yamlpersistentvolumeclaim/raw-block-pvc created[root@qd01-stop-k8s-master001 UseRBD]# kubectl get pvcNAME            STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGEraw-block-pvc   Bound    pvc-84bf2ffb-7aee-41bd-9e6d-614c9f29eab4   1Gi        RWO            rbd            39s

4、测试动态分配PVC
创建demo-statefulset-csi.yaml

apiVersion: apps/v1kind: StatefulSetmetadata:  name: demo-nginx  namespace: default  labels:    app: demo-nginxspec:  serviceName: demo-nginx  replicas: 2  selector:    matchLabels:      app: demo-nginx  template:    metadata:      labels:        app: demo-nginx    spec:      terminationGracePeriodSeconds: 180      initContainers:        - name: init          image: busybox          command: ["chmod","777","-R","/data"]          imagePullPolicy: Always          volumeMounts:          - name: volume            mountPath: /data      containers:      - name: demo-nginx        image: nginx        ports:        - containerPort: 80          name: port        volumeMounts:        - name: volume          mountPath: /data  volumeClaimTemplates:  - metadata:      name: volume    spec:      accessModes: ["ReadWriteOnce"]      storageClassName: rbd      resources:        requests:          storage: 5Gi[root@qd01-stop-k8s-master001 UseRBD]# kubectl apply -f demo-statefulset-csi.yamlstatefulset.apps/demo-nginx created

5、验证可以看到,pvs自动创建好,并且正常挂载到pod中

[root@qd01-stop-k8s-master001 UseRBD]# kubectl get pvcNAME                  STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGEvolume-demo-nginx-0   Bound    pvc-b0e3c919-10ad-49f7-a225-4337c07133ea   5Gi        RWO            rbd            6m37svolume-demo-nginx-1   Bound    pvc-cb526baa-62ae-43ee-a544-eb1655c9c8c6   5Gi        RWO            rbd            2m24s[root@qd01-stop-k8s-master001 UseRBD]# kubectl get po NAME           READY   STATUS    RESTARTS   AGEdemo-nginx-0   1/1     Running   0          5m5sdemo-nginx-1   1/1     Running   0          2m31s进入到其中一个pod中可以看到,挂载了一个/dev/rbd2块存储,大小为制定的5G[root@qd01-stop-k8s-master001 UseRBD]# kubectl exec -ti demo-nginx-0 /bin/shkubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.# df -hFilesystem      Size  Used Avail Use% Mounted on/dev/rbd2       5.0G   38M  5.0G   1% /data

PS:文章会同步到dev.kubeops.net

  推荐站点

  • At-lib分类目录At-lib分类目录

    At-lib网站分类目录汇集全国所有高质量网站,是中国权威的中文网站分类目录,给站长提供免费网址目录提交收录和推荐最新最全的优秀网站大全是名站导航之家

    www.at-lib.cn
  • 中国链接目录中国链接目录

    中国链接目录简称链接目录,是收录优秀网站和淘宝网店的网站分类目录,为您提供优质的网址导航服务,也是网店进行收录推广,站长免费推广网站、加快百度收录、增加友情链接和网站外链的平台。

    www.cnlink.org
  • 35目录网35目录网

    35目录免费收录各类优秀网站,全力打造互动式网站目录,提供网站分类目录检索,关键字搜索功能。欢迎您向35目录推荐、提交优秀网站。

    www.35mulu.com
  • 就要爱网站目录就要爱网站目录

    就要爱网站目录,按主题和类别列出网站。所有提交的网站都经过人工审查,确保质量和无垃圾邮件的结果。

    www.912219.com
  • 伍佰目录伍佰目录

    伍佰网站目录免费收录各类优秀网站,全力打造互动式网站目录,提供网站分类目录检索,关键字搜索功能。欢迎您向伍佰目录推荐、提交优秀网站。

    www.wbwb.net