前面幾天已經將Ceph安裝好並建立CephFS及一個CephFS的使用者,接下來就要部署CephFS了,kubernetes安裝的部分在剛開賽時就有介紹,這邊就不再贅述了。
git clone https://github.com/ceph/ceph-csi.git
cd ceph-csi/examples/cephfs/
./plugin-deploy.sh ../../deploy/cephfs/kubernetes
執行完會產生3個pod
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
---
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
---
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
---
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
完成部署後接下來驗證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://github.com/ceph/ceph-csi
https://kubernetes.io/blog/2019/01/15/container-storage-interface-ga/