### 一、Github仓库手动安装 - github 仓库 https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner #### 1. clone 仓库 ```bash git clone https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner cd nfs-subdir-external-provisioner/deploy ``` #### 2. 修改deployment和rbac - vim deployment.yaml ![image-20231028145130015](https://blog-heysq-1255479807.cos.ap-beijing.myqcloud.com/blog/note/image-20231028145130015.png) - vim rbac.yaml 替换namespace为你想部署pod的空间 ![image-20231028145243771](https://blog-heysq-1255479807.cos.ap-beijing.myqcloud.com/blog/note/image-20231028145243771.png) - 执行以下命令 ```bash kubectl apply -f rbac.yaml kubectl apply -f deployment.yaml ``` #### 3. 创建存储类 ```bash kubectl apply -f class.yaml ``` ![image-20231028145331651](https://blog-heysq-1255479807.cos.ap-beijing.myqcloud.com/blog/note/image-20231028145331651.png) #### 4. 部署pvc和pod ```bash kubectl apply -f test-claim.yaml kubectl apply -f test-pod.yaml ``` #### 5. pod的存储卷生命和pvc声明组合 ```yaml --- apiVersion: v1 kind: Service metadata: name: nginx labels: app: nginx spec: ports: - port: 80 name: web clusterIP: None selector: app: nginx --- apiVersion: apps/v1 kind: StatefulSet # StatefulSet 类型的资源 metadata: name: web # StatefulSet 对象的名字 spec: serviceName: "nginx" # 使用哪个 service 来管理 dns replicas: 2 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.14 ports: # 容器内部要暴露的端口 - containerPort: 80 # 具体暴露的端口号 name: web # 该端口配置的名字 volumeMounts: - mountPath: /usr/share/nginx/html name: nginx-test-pvc volumeClaimTemplates: - metadata: name: nginx-test-pvc spec: storageClassName: nfs-client accessModes: - ReadWriteMany resources: requests: storage: 1Gi ``` ### 二、helm 安装 ```bash helm repo add nfs-subdir-external-provisioner https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner/ helm install nfs-subdir-external-provisioner nfs-subdir-external-provisioner/nfs-subdir-external-provisioner --set nfs.server=192.168.0.12 --set nfs.path=/volume1/share ```