系統(tǒng):centos7
kubernetes:v1.19
1、準(zhǔn)備nfs-server
選擇一臺(tái)服務(wù)器安裝nfs-server
$ yum -y install nfs-utils rpcbind
修改nfs-server的配置
$ mkdir -p /data/nfs$ chmod 0755 /data/nfs$ echo “/data/nfs 172.30.32.0/22(rw,no_root_squash,no_all_squash,sync)” >> /etc/exports
參數(shù)有:
- rw、ro:該目錄分享權(quán)限是可讀寫(read-write)或只讀(read-only)
- sync、async:sync代表數(shù)據(jù)會(huì)同步寫入到內(nèi)存和硬盤中,async表示數(shù)據(jù)會(huì)暫存在內(nèi)存,而非直接寫入硬盤
- no_root_squash、root_squash:客戶端root的身份會(huì)由root_squash的設(shè)定壓縮成nfsnobody。如果想開(kāi)放客戶端使用root身份來(lái)操作服務(wù)器的文件系統(tǒng),需要開(kāi)啟no_root_squash
- no_all_squash、all_squash:客戶端的身份被壓縮成nobody(nfsnobody),如果想開(kāi)放客戶端使用者身份,需要開(kāi)啟no_all_squash
- anonuid、anongid:anno是anonymous(匿名者),uid和gid是用戶id和組id,設(shè)置目錄的權(quán)限
然后使配置生效
$ exportfs -r$ systemctl enable rpcbind$ systemctl enable nfs-server
查看掛載情況
$ showmount -e localhostExport list for localhost:/data/nfs 172.30.32.0/22
2、在kubernetes上安裝nfs-client
在所有節(jié)點(diǎn)安裝nfs客戶端
$ yum -y install nfs-utils$ showmount -e 172.30.33.193Export list for 172.30.33.193:/data/nfs 172.30.32.0/22
此時(shí)在另一臺(tái)服務(wù)器上已經(jīng)可以查看到nfs掛載的目錄。
helm安裝nfs-client
$ helm repo add nfs-subdir-external-provisioner https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner/$ helm install -n kube-system nfs-client nfs-subdir-external-provisioner/nfs-subdir-external-provisioner –set nfs.server=172.30.33.193 –set nfs.path=/data/nfs –set storageClass.defaultClass=true $ helm list -n kube-systemNAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSIONnfs-client kube-system 1 2022-06-13 16:56:00.304704446 +0800 CST deployed nfs-subdir-external-provisioner-4.0.11 4.0.2
查看storageclass
$ kubectl get scNAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGEnfs-client (default) cluster.local/nfs-client-nfs-client-provisioner Delete Immediate false 18h
已經(jīng)安裝完畢,申請(qǐng)pvc時(shí)會(huì)通過(guò)storageclass自動(dòng)申請(qǐng)pv
$ cat pvc.yamlapiVersion: v1kind: PersistentVolumeClaimmetadata: name: pvc1spec: accessModes: – ReadWriteMany resources: requests: storage: 100Mi$ kubectl apply -f pvc.yamlpersistentvolumeclaim/pvc1 created$ kubectl get pvcNAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGEpvc1 Bound pvc-c2c45851-c843-4198-9dec-ed5f66308e93 100Mi RWX nfs-client 4s$ # kubectl get pvc pvc1 -o yamlapiVersion: v1kind: PersistentVolumeClaimspec: accessModes: – ReadWriteMany resources: requests: storage: 100Mi storageClassName: nfs-client volumeMode: Filesystem volumeName: pvc-c2c45851-c843-4198-9dec-ed5f66308e93status: accessModes: – ReadWriteMany capacity: storage: 100Mi phase: Bound
可以看到pvc已經(jīng)綁定了storageClassName