09--在k8s中安装nfs csi driver实现动态存储
在k8s中安装nfs csi driver实现动态存储
·
09--在k8s中安装nfs csi driver
1 安装nfs csi driver
- 官网https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/docs/install-csi-driver-v3.1.0.md
1.1 安装nfs-server
# a. 创建nfs命名空间
kubectl create namespace nfs
# b. 在nfs命名空间安装nfs-server
root@master1:~# kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/deploy/example/nfs-provisioner/nfs-server.yaml --namespace nfs
service/nfs-server created
deployment.apps/nfs-server created
# c. 移除nfs-server方法
kubectl delete -f https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/deploy/example/nfs-provisioner/nfs-server.yaml --namespace nfs
# d. 查看nfs-server的pod,状态为running就没问题
root@master1:~# kubectl get pods -n nfs -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nfs-server-5847b99d99-7htpx 1/1 Running 0 50s 10.244.1.63 node1.lec.org <none> <none>
# e. 查看nfs-server的svc
root@master1:~# kubectl get svc -n nfs -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
nfs-server ClusterIP 10.111.69.230 <none> 2049/TCP,111/UDP 103s app=nfs-server
1.2 部署nfs csi driver
# a. 安装
root@master1:~# curl -skSL https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/v3.1.0/deploy/install-driver.sh | bash -s v3.1.0 --
Installing NFS CSI driver, version: v3.1.0 ...
serviceaccount/csi-nfs-controller-sa created
clusterrole.rbac.authorization.k8s.io/nfs-external-provisioner-role created
clusterrolebinding.rbac.authorization.k8s.io/nfs-csi-provisioner-binding created
csidriver.storage.k8s.io/nfs.csi.k8s.io created
deployment.apps/csi-nfs-controller created
daemonset.apps/csi-nfs-node created
NFS CSI driver installed successfully.
# 涉及的nfs-csi镜像
mcr.microsoft.com/k8s/csi/nfs-csi:v3.1.0
# b. 查看pod状态
root@master1:~# kubectl -n kube-system get pod -o wide -l app=csi-nfs-controller
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
csi-nfs-controller-65cf7d587-j4fc9 3/3 Running 0 20s 10.0.0.72 node2.lec.org <none> <none>
csi-nfs-controller-65cf7d587-x5wzh 3/3 Running 0 20s 10.0.0.71 node1.lec.org <none> <none>
root@master1:~# kubectl -n kube-system get pod -o wide -l app=csi-nfs-node
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
csi-nfs-node-l885s 3/3 Running 0 35s 10.0.0.71 node1.lec.org <none> <none>
csi-nfs-node-m25vg 3/3 Running 0 35s 10.0.0.70 master1.lec.org <none> <none>
csi-nfs-node-rqprx 3/3 Running 0 35s 10.0.0.72 node2.lec.org <none> <none>
# c. 删除nfs csi driver
curl -skSL https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/v3.1.0/deploy/uninstall-driver.sh | bash -s v3.1.0 --
1.3 创建storageclass,配置CSI Driver 引用前面部署的nfs server作为存储后端
# a. 创建sc的yaml
root@master01:~/yaml# cat storageclass-nfs.yaml
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: nfs-csi
provisioner: nfs.csi.k8s.io
parameters:
#server: nfs-server.default.svc.cluster.local
server: nfs-server.nfs.svc.cluster.local
share: /
reclaimPolicy: Retain
volumeBindingMode: Immediate
mountOptions:
- hard
- nfsvers=4.1
root@master01:~/yaml# kubectl apply -f storageclass-nfs.yaml
# b. 查看sc
root@master1:~/yaml# kubectl get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
nfs-csi nfs.csi.k8s.io Retain Immediate false 3s
# c. 删除的操作
kubectl delete -f storageclass-nfs.yaml
1.4 创建pvc测试动态绑定pv
# a. 编辑pvc的yaml
root@master01:~/yaml# cat pvc-nfs-csi-dynamic.yaml
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-nfs-dynamic
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi
storageClassName: nfs-csi
# b. 创建
kubectl apply -f pvc-nfs-csi-dynamic.yaml
# c. 验证pvc,发现绑定了pv
root@master01:~/yaml# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
pvc-nfs-dynamic Bound pvc-972d5917-3dd4-47e9-bca4-77cd9ea7e0af 10Gi RWX nfs-csi 50s
# d. 查看pv
root@master01:~/yaml# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pvc-972d5917-3dd4-47e9-bca4-77cd9ea7e0af 10Gi RWX Retain Bound default/pvc-nfs-dynamic nfs-csi 118s
# e. 删除
# 删除pv
kubectl delete pv pvc-972d5917-3dd4-47e9-bca4-77cd9ea7e0af
# 删除pvc
kubectl delete -f pvc-nfs-csi-dynamic.yaml
更多推荐
已为社区贡献3条内容
所有评论(0)