NFS动态制备

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
posted @ 2024-06-26 16:43  FuShudi  阅读(30)  评论(0编辑  收藏  举报