安装NFS高可用集群

安装 nfs-client-provisioner

curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3

chmod 700 get_helm.sh

./get_helm.sh

helm repo add azure http://mirror.azure.cn/kubernetes/charts/

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

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nfs-pvc-test
spec:
  storageClassName: "nfs-hw"
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 10Gi

测试

kubectl apply -f nfs-test.yaml

apiVersion: batch/v1
kind: Job
metadata:
  name: nfsjob
spec:
  template:
    spec:
      containers:
      - name: bbox1
        image: busybox
        args:
        - /bin/sh
        - -c
        - echo "1231231231" > /nfs-data/hello
        volumeMounts:
        - mountPath: "/nfs-data"
          name: nfsdata
      restartPolicy: Never
      volumes:
      - name: nfsdata
        persistentVolumeClaim:
          claimName: nfs-pvc-test

end

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

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