iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 30
1
自我挑戰組

SDN/NFV 網路虛擬化調度平台系列 第 30

Day30 - 部署Kubenete CSI plugin(CephFS)

前言

前面幾天已經將Ceph安裝好並建立CephFS及一個CephFS的使用者,接下來就要部署CephFS了,kubernetes安裝的部分在剛開賽時就有介紹,這邊就不再贅述了。

部署步驟

  1. 先到官方的Github將ceph-csi專案clone下來
git clone https://github.com/ceph/ceph-csi.git
  1. cd到專案內的/examples/cephfs執行部屬的shell檔
cd ceph-csi/examples/cephfs/
./plugin-deploy.sh ../../deploy/cephfs/kubernetes

執行完會產生3個pod
https://ithelp.ithome.com.tw/upload/images/20191015/20121070u6FZXSS1Br.png

  1. 建立namespace
kubectl create namespace csi-test

接下來修改以下幾個yaml檔並照secret,storageclass,pvc,pod的順序部署
4. secret.yaml

---
apiVersion: v1
kind: Secret
metadata:
  name: csi-cephfs-secret
  namespace: csi-test
data:
  # Required if provisionVolume is set to false
  userID: amlhbnF1bg==
  userKey: {userKey}

  # Required if provisionVolume is set to true
  adminID: amlhbnF1bg==
  adminKey: {adminKey}

ID的部分為CephFS的使用者名稱(使用base64編碼),key為其對應的key

kubectl create -f secret.yaml
  1. storageclass.yaml
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: csi-cephfs
  namespace: csi-test
provisioner: cephfs.csi.ceph.com
parameters:
  monitors: ceph-monitor-ip:6789

  provisionVolume: "false"

  pool: cephfs_data

  rootPath: /test

  csi.storage.k8s.io/provisioner-secret-name: csi-cephfs-secret
  csi.storage.k8s.io/provisioner-secret-namespace: csi-test
  csi.storage.k8s.io/node-stage-secret-name: csi-cephfs-secret
  csi.storage.k8s.io/node-stage-secret-namespace: csi-test

reclaimPolicy: Delete

monitors填入ceph monitor的ip
pool填入ceph cluster內創立的cephfs pool
rootPath為mount到ceph的目錄

kubectl create -f storageclass.yaml
  1. pvc.yaml
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: csi-cephfs-pvc
  namespace: csi-test
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Gi
  storageClassName: csi-cephfs

storageClassName對應到剛剛所創建的storageClass的名稱

kubectl create -f pvc.yaml
  1. pod.yaml
---
apiVersion: v1
kind: Pod
metadata:
  name: csicephfs-demo-pod
  namespace: csi-test
spec:
  containers:
    - name: web-server
      image: nginx
      volumeMounts:
        - name: mypvc
          mountPath: /var/lib/www
  volumes:
    - name: mypvc
      persistentVolumeClaim:
        claimName: csi-cephfs-pvc
        readOnly: false

mountPath為pod內要mount到ceph的目錄
claimName對應到剛剛所創建的pvc的名稱

kubectl create -f pod.yaml

https://ithelp.ithome.com.tw/upload/images/20191015/20121070hdywrP4wPl.png

驗證

完成部署後接下來驗證CephFS是否掛載成功

先進到pod內

kubectl exec -ti csicephfs-demo-pod -n csi-test bash

進到設定mount的路徑新增一個檔案

cd /var/lib/www
touch abc

接下來到另外一個node新增一個目錄再mount到ceph的目錄

mkdir mnt
mount -t ceph {monitor-ip}:6789:/test /home/ubuntu/mnt -o name={cephfs-name},secret={ceph-fs-secret}
cd mnt

完成後進入/mnt就能夠看到剛剛在kubernetes的pod內新增的檔案abc了
https://ithelp.ithome.com.tw/upload/images/20191015/201210702Zkzm0Pot0.png

Reference

https://github.com/ceph/ceph-csi
https://kubernetes.io/blog/2019/01/15/container-storage-interface-ga/


上一篇
Day29 - CephFS介紹與實作
系列文
SDN/NFV 網路虛擬化調度平台30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

0
阿展展展
iT邦好手 1 級 ‧ 2020-02-07 08:42:43

恭喜完賽

我要留言

立即登入留言