1. 建立nfs server
cat /etc/exports /data/nfs_pro 192.168.31.0/24(rw,no_root_squash)
2.建立sa,绑定权限
kubectl create sa nfs-provisioner kubectl create clusterrolebinding nfs-provisioner-clusterolebinding --clusterrole=cluster-admin --serviceaccount=default:nfs-provisioner
3.导入provisioner镜像 ,创建provisioner服务
docker pull registry.cn-beijing.aliyuncs.com/mydlq/nfs-subdir-external-provisioner:v4.0.0
kind: Deployment apiVersion: apps/v1 metadata: name: nfs-provisioner spec: selector: matchLabels: app: nfs-provisioner replicas: 1 strategy: type: Recreate template: metadata: labels: app: nfs-provisioner spec: serviceAccount: nfs-provisioner containers: - name: nfs-provisioner image: registry.cn-beijing.aliyuncs.com/mydlq/nfs-subdir-external-provisioner:v4.0.0 imagePullPolicy: IfNotPresent volumeMounts: - name: nfs-client-root mountPath: /persistentvolumes env: - name: PROVISIONER_NAME value: example.com/nfs // 后面会用到 - name: NFS_SERVER value: 192.168.40.180 - name: NFS_PATH value: /data/nfs_pro/ volumes: - name: nfs-client-root nfs: server: 192.168.40.180 path: /data/nfs_pro/View Code
4.创建nfs storageclass
apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: nfs provisioner: example.com/nfs //上一步环境变量里的名称
kubectl get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
nfs example.com/nfs Delete Immediate false 70s