一、前提說明
1、說明:
NFS client provisioner 利用 NFS Server 給 Kubernetes 作為持久存儲的后端,並且動態提供PV。
默認 rancher 2 的存儲類中的提供者不包含NFS,需要手動添加;添加方式有兩種:
1)從應用商店直接安裝配置 nfs-client-provisioner (需手動添加倉庫,該倉庫是從helm官方代碼庫復制自己需要的應用代碼並定制的)
2)手動創建 nfs-client-provisioner 存儲類,步驟如下:
2、前提:
1)安裝好 nfs server(172.31.49.9 ),並分享目錄(k8snfs_test)
2)安裝有 helm 的 master 主機上安裝 git
yum install -y git
3)安裝rpcbind
yum install -y rpcbind
systemctl enable rpcbind
systemctl start rpcbind
二、安裝 nfs-client-provisioner
參考:https://github.com/helm/charts/tree/master/stable/nfs-client-provisioner
在安裝 helm 的主機上操作:
git clone https://github.com/helm/charts.git cd charts/ helm install stable/nfs-client-provisioner --set nfs.server=172.31.49.9 --set nfs.path=/k8snfs_test
執行結果如下:
nfs client 會以容器的形式運行。同時在集群的存儲類中創建了 nfs-client 類
三、驗證
1、啟動一個 pod,添加存儲卷(創建新的 PV,存儲類選擇 nfs-client,保存)。
2、然后填寫PVC卷名,容器路徑。
3、進入容器,創建一個測試文件
4、進入 NFS server 中查看分享的 k8snfs_test 目錄可看到自動創建了持久卷目錄。
[root@DL-Dev4-49-9 k8snfs_test]# ll total 4 drwxrwxrwx 2 root root 4096 Jun 21 15:42 default-pvc-g55h2-pvc-a002261e-93f7-11e9-a843-025f44ec7002 [root@DL-Dev4-49-9 k8snfs_test]# [root@DL-Dev4-49-9 k8snfs_test]# ll default-pvc-g55h2-pvc-a002261e-93f7-11e9-a843-025f44ec7002/ total 0 -rw-r--r-- 1 root root 0 Jun 21 15:42 111.txt
5、在rancher的持久卷中也可以看到該持久卷
四、NFS性能調整
Linux nfs客戶端對於同時發起的NFS請求數量進行了控制,若該參數配置較小會導致IO性能較差,請查看該參數:
cat /proc/sys/sunrpc/tcp_slot_table_entries
默認編譯的內核該參數最大值為256,可適當提高該參數的值來取得較好的性能,請以root身份執行以下命令:
echo "options sunrpc tcp_slot_table_entries=128" > /etc/modprobe.d/sunrpc.conf echo "options sunrpc tcp_max_slot_table_entries=128" > /etc/modprobe.d/sunrpc.conf sysctl -w sunrpc.tcp_slot_table_entries=128
修改完成后,您需要重新掛載文件系統或重啟機器。
參考:
https://yq.aliyun.com/articles/501417
https://github.com/helm/charts/tree/master/stable/nfs-client-provisioner