前提条件

在所有节点安装nfs-utils并启动相关服务。

1.NFS服务端192.168.1.210新建一个挂载目录

echo "/home/nfs *(rw,async,no_root_squash)" >> /etc/exports
exportfs -r
showmount -e localhost

2.安装nfs-client

2.1 helm安装nfs-client

helm install stable/nfs-client-provisioner --name test-storageclass --set nfs.server=192.168.1.210 --set nfs.path=/home/nfs

2.2 yaml安装nfs-client

创建nfs-client.yaml

replicaCount: 1
strategyType: Recreate
 
image:
  repository: quay.io/external_storage/nfs-client-provisioner
  tag: v3.1.0-k8s1.11
  pullPolicy: IfNotPresent
 
nfs:
  server: 192.168.1.210
  path: /home/nfs
  mountOptions:
 
storageClass:
  create: true
  defaultClass: false
  name: nfs-client
  allowVolumeExpansion: true
  reclaimPolicy: Delete
  archiveOnDelete: true
 
rbac:
  create: true
 
podSecurityPolicy:
  enabled: false
 
kubectl apply -f nfs-client.yaml

3 创建PVC测试,创建test-pvc.yaml


apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: testclaim
spec:
  storageClassName: "nfs-client"
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 10Mi
 


kubectl apply -f test-pvc.yaml

4 查看结果

# kubectl get sc
NAME         PROVISIONER                                              AGE
nfs-client   cluster.local/test-storageclass-nfs-client-provisioner   36m
# kubectl get pv,pvc
NAME                                                        CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS        CLAIM                 STORAGECLASS    REASON   AGE
persistentvolume/pvc-d9bdfa45-6417-4ad9-bbf0-02301f928342   10Mi       RWX            Delete           Bound         default/testclaim     nfs-client               33m
 
NAME                              STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
persistentvolumeclaim/testclaim   Bound    pvc-d9bdfa45-6417-4ad9-bbf0-02301f928342   10Mi       RWX   
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐