安装NFS高可用集群

安装 nfs-client-provisioner

  1. curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
  2. chmod 700 get_helm.sh
  3. ./get_helm.sh
  4. helm repo add azure http://mirror.azure.cn/kubernetes/charts/
  5. helm install nfs-storage azure/nfs-client-provisioner --set nfs.server="172.12.17.200" --set nfs.path=/fs/nsf-data --set storageClass.name=nfs-hw

创建PVC

kubectl apply -f nfs-pvc.yaml

  1. apiVersion: v1
  2. kind: PersistentVolumeClaim
  3. metadata:
  4. name: nfs-pvc-test
  5. spec:
  6. storageClassName: "nfs-hw"
  7. accessModes:
  8. - ReadWriteMany
  9. resources:
  10. requests:
  11. storage: 10Gi

测试

kubectl apply -f nfs-test.yaml

  1. apiVersion: batch/v1
  2. kind: Job
  3. metadata:
  4. name: nfsjob
  5. spec:
  6. template:
  7. spec:
  8. containers:
  9. - name: bbox1
  10. image: busybox
  11. args:
  12. - /bin/sh
  13. - -c
  14. - echo "1231231231" > /nfs-data/hello
  15. volumeMounts:
  16. - mountPath: "/nfs-data"
  17. name: nfsdata
  18. restartPolicy: Never
  19. volumes:
  20. - name: nfsdata
  21. persistentVolumeClaim:
  22. claimName: nfs-pvc-test

end

  • 接下来去看看 NFS 服务器上是否有对应文件文件

K8S 集群是 v1.20+,在 nfs provisioner 创建 pvc 时,nfs provisioner 会报错