|NO.Z.00246|——————————|CloudNative|——|KuberNetes&儲存進階.V12|-------------------------------------------------------|Ceph.v06|ceph測試|ceph塊儲存|
阿新 • • 發佈:2022-03-31
[CloudNative:KuberNetes&儲存進階.V12] [Applications.KuberNetes] [|DevOps|k8s|雲原生儲存及儲存進階|**3節點.下**|ceph儲存叢集的測試|
一、ceph塊儲存的使用:建立StorageClass和ceph的儲存池
### --- 注:塊儲存一般用於一個Pod掛載一塊儲存使用,相當於一個伺服器新掛了一個盤,只給一個應用使用。 ~~~ # 進入StorageClass配置檔案目錄並修改配置引數 ~~~ 注:因為我是試驗環境,所以將副本數設定成了2(不能設定為1),生產環境最少為3,且要小於等於osd的數量,其他配置可以參考視訊: [root@k8s-master01 ceph]# pwd /root/rook/cluster/examples/kubernetes/ceph [root@k8s-master01 ceph]# vim csi/rbd/storageclass.yaml spec: failureDomain: host replicated: size: 2
### --- 建立StorageClass和儲存池
[root@k8s-master01 ceph]# kubectl create -f csi/rbd/storageclass.yaml -n rook-ceph
cephblockpool.ceph.rook.io/replicapool created
storageclass.storage.k8s.io/rook-ceph-block created
二、此時可以在ceph dashboard檢視到該Pool,如果沒有顯示說明沒有建立成功### --- 檢視建立的cephblockpool和storageClass(StorageClass沒有namespace隔離性) [root@k8s-master01 ceph]# kubectl get cephblockpool -n rook-ceph NAME AGE replicapool 27s [root@k8s-master01 ceph]# kubectl get sc NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE rook-ceph-block rook-ceph.rbd.csi.ceph.com Delete Immediate true 32s
三、掛載測試:建立一個MySQL服務
### --- 進入到k8s安裝目錄下
[root@k8s-master01 ceph]# cd /root/rook/cluster/examples/kubernetes
### --- 建立一個mysql服務 [root@k8s-master01 kubernetes]# kubectl create -f mysql.yaml service/wordpress-mysql created persistentvolumeclaim/mysql-pv-claim created deployment.apps/wordpress-mysql created
### --- mysql.yaml檔案下有一個PVC配置
~~~ pvc會連線剛才建立的storageClass,然後動態建立pv,然後連線到ceph建立對應的儲存
~~~ 之後建立pvc只需要指定storageClassName為剛才建立的StorageClass名稱即可連線到rook的ceph。如果是statefulset,只需要將volumeTemplateClaim裡面的Claim名稱改為StorageClass名稱即可動態建立Pod,
~~~ claimName為pvc的名稱
~~~ 因為MySQL的資料不能多個MySQL例項連線同一個儲存,所以一般只能用塊儲存。相當於新加了一塊盤給MySQL使用。
[root@k8s-master01 kubernetes]# vim mysql.yaml
spec:
storageClassName: rook-ceph-block
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
spec:
containers:
- image: mysql:5.6
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: changeme
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-pv-claim
### --- 建立完成後可以檢視建立的po、pvc和pv
[root@k8s-master01 kubernetes]# kubectl get po
NAME READY STATUS RESTARTS AGE
busybox 1/1 Running 1 63m
wordpress-mysql-6965fc8cc8-fvtrt 1/1 Running 0 2m59s
[root@k8s-master01 kubernetes]# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
mysql-pv-claim Bound pvc-a22e54cf-9d96-4070-b3a7-90a2fa73c249 20Gi RWO rook-ceph-block 3m8s
[root@k8s-master01 kubernetes]# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pvc-a22e54cf-9d96-4070-b3a7-90a2fa73c249 20Gi RWO Delete Bound default/mysql-pv-claim rook-ceph-block 3m9s
四、此時在ceph dashboard上面也可以檢視到對應的image===============================END===============================
Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart ——W.S.Landor
來自為知筆記(Wiz)