nfs-csi驱动部署
github:https://github.com/kubernetes-csi/csi-driver-nfs
部署文档:https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/deploy/example/README.md
部署
1)克隆仓库
export https_proxy=http://frp1.freefrp.net:16324
git clone --depth 1 https://github.com/kubernetes-csi/csi-driver-nfs.git
cd csi-driver-nfs
version=v4.4.0
wget https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/${version}/deploy/example/nfs-provisioner/nfs-server.yaml
unset https_proxy
2)下载镜像替换脚本
wget https://files.cnblogs.com/files/blogs/731344/rep-docker-img.sh
sh rep-docker-img.sh
3)部署nfs-csi
注:默认源码里面把kubelet的数据目录写死成/var/lib/kubelet了,如果有改过kubelet数据目录,可以执行这个脚本更改
wget https://files.cnblogs.com/files/blogs/731344/rep-kbdata-dir.sh
sh rep-kubdata-dir.sh
./deploy/install-driver.sh ${version} local
4)部署nfs-server
方法1:直接使用k8s的pod当做nfs服务
kubectl apply -f nfs-server.yaml
方法2:使用物理机/虚拟机搭建nfs服务
mkdir -p /data/nfs
chown nobody:nobody /data/nfs
chmod 0777 /data/nfs
yum install -y nfs-utils
echo '/data/nfs 2.2.2.0/24(rw,sync,no_subtree_check)' >> /etc/exports
systemctl enable --now nfs-server.service
exportfs -av
showmount -e 127.0.0.1
5)创建存储类
方法1:pod方式运行nfs-server
kubectl apply -f - <<eof
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: nfs-csi
provisioner: nfs.csi.k8s.io
parameters:
#nfs-server的svc域名,如果部署在非默认的ns,则需要修改
server: nfs-server.default.svc.cluster.local
share: /
# 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
eof
方法2:对应虚拟机搭建nfs-server
kubectl apply -f - <<EOF
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: nfs-csi
provisioner: nfs.csi.k8s.io
parameters:
server: 2.2.2.45
share: /data/nfs
reclaimPolicy: Retain
volumeBindingMode: Immediate
mountOptions:
- hard
- nfsvers=4.1
EOF
6)测试动态pvc申请
kubectl apply -f - <<EOF
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-nfs-dynamic
spec:
storageClassName: nfs-csi
accessModes: [ReadWriteOnce]
resources:
requests:
storage: 100Mi
EOF
7)卸载/清理
kubectl delete pvc pvc-nfs-dynamic
#卸载驱动
./deploy/uninstall-driver.sh ${version} local