目錄
- NFS動態製備
- 1. 拉取程式碼
- 2. 修改映象倉庫為阿里雲
- 2.1 拉取映象
- 3. 開始安裝csi
- 4. 檢視pod狀態
- 5. 建立sc
- 5.1 修改storageclass-nfs.yaml
- 6. 將sc設為預設
- 7. 測試使用
NFS動態製備
1. 拉取程式碼
從github上拉取程式碼,這一步會因為網路原因造成失敗,多試幾次就好
[root@master ~]# git clone https://github.com/kubernetes-csi/csi-driver-nfs.git
[root@master ~]# cd csi-driver-nfs/
2. 修改映象倉庫為阿里雲
[root@master csi-driver-nfs]# cp -a deploy/v4.6.0/ deploy/v4.6.0-bak
[root@master csi-driver-nfs]# sed -i 's@registry.k8s.io/sig-storage@registry.aliyuncs.com/google_containers@g' deploy/v4.6.0/*.yaml
2.1 拉取映象
因為有一個映象阿里雲裡面好像沒有,需要從別的地方拉取,拉取完了之後我們將映象的tag改為阿里雲的,這樣就不需要去改動yaml檔案了
[root@master csi-driver-nfs]# docker pull registry.cn-hangzhou.aliyuncs.com/image-storage/nfspluginnfsplugin:v4.6.0
[root@master csi-driver-nfs]# docker tag registry.cn-hangzhou.aliyuncs.com/image-storage/nfspluginnfsplugin:v4.6.0 registry.aliyuncs.com/google_containers/nfsplugin:v4.6.0
3. 開始安裝csi
[root@master csi-driver-nfs]# ./deploy/install-driver.sh v4.6.0 local
4. 檢視pod狀態
[root@master csi-driver-nfs]# kubectl get pods -n kube-system |grep nfs
csi-nfs-controller-6666d547dc-scpvc 4/4 Running 0 15s
csi-nfs-node-p4bk7 3/3 Running 0 15s
當2個pod都running之後我們去建立sc
5. 建立sc
[root@master csi-driver-nfs]# cd deploy/example/
[root@master example]# ls
cloning fsgroup nginx-pod-nfs.yaml pv-nfs-csi.yaml statefulset.yaml
daemonset-nfs-ephemeral.yaml nfs-provisioner pvc-nfs-csi-dynamic.yaml README.md storageclass-nfs.yaml
deployment.yaml nginx-pod-inline-volume.yaml pvc-nfs-csi-static.yaml snapshot
5.1 修改storageclass-nfs.yaml
[root@master example]# cat storageclass-nfs.yaml
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: nfs-csi
provisioner: nfs.csi.k8s.io
parameters:
server: 192.168.0.10
share: /nfs
# csi.storage.k8s.io/provisioner-secret is only needed for providing mountOptions in DeleteVolume
# csi.storage.k8s.io/provisioner-secret-name: "mount-options"
# csi.storage.k8s.io/provisioner-secret-namespace: "default"
reclaimPolicy: Delete
volumeBindingMode: Immediate
mountOptions:
- nfsvers=4.1
- 將server 改為nfs伺服器的地址
- 將share 改為nfs共享的目錄
[root@master example]# kubectl apply -f storageclass-nfs.yaml
[root@master example]# kubectl get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
csi-rbd-sc rbd.csi.ceph.com Delete Immediate true 3d6h
nfs-csi nfs.csi.k8s.io Delete Immediate false 16s
然後就會有一個nfs-csi的sc了
6. 將sc設為預設
[root@master example]# kubectl edit sc nfs-csi
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
annotations:
storageclass.kubernetes.io/is-default-class: "true"
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"storage.k8s.io/v1","kind":"StorageClass","metadata":{"annotations":{},"name":"nfs-csi"},"mountOptions":["nfsvers=4.1"],"parameters":{"server":"192.168.0.10","share":"/nfs"},"provisioner":"nfs.csi.k8s.io","reclaimPolicy":"Delete","volumeBindingMode":"Immediate"}
creationTimestamp: "2024-06-26T08:22:50Z"
在註釋裡面加入 storageclass.kubernetes.io/is-default-class: "true"
[root@master example]# kubectl get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
csi-rbd-sc rbd.csi.ceph.com Delete Immediate true 3d6h
nfs-csi (default) nfs.csi.k8s.io Delete Immediate false 50s
然後他的後面就會出現一個default
7. 測試使用
編寫一個pvc的yaml檔案
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: sc-pvc
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 20Gi
[root@master euler]# kubectl apply -f pvc-test.yaml
persistentvolumeclaim/sc-pvc created
[root@master euler]# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
sc-pvc Bound pvc-8f3ce5f8-79a6-40a7-82e3-a1a6d894d3c3 20Gi RWO nfs-csi 3s