创建PV
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 apiVersion: v1 kind: PersistentVolume metadata: name: pv0001 spec: capacity: storage: 5Gi volumeMode: Filesystem accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Recycle storageClassName: slow mountOptions: - hard - nfsvers=4.1 nfs: path: /home/nfs/rw/test-pv server: 192.168 .192 .134
在node1中创建/data/nfs/rw/test-pv路径,然后创建pv
使用get 查看
1 2 3 [root@k8s-master nfs] NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE pv0001 5Gi RWO Recycle Available slow 14s
创建pvc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 apiVersion: v1 kind: PersistentVolumeClaim metadata: name: nfs-pvc spec: accessModes: - ReadWriteOnce volumeMode: Filesystem resources: requests: storage: 8Gi storageClassName: slow
通过get查看他们的状态,
1 2 3 4 5 6 [root@k8s-master ~] NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE pv0001 5Gi RWX Recycle Bound default/nfs-pvc slow 159m [root@k8s-master ~] NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE nfs-pvc Bound pv0001 5Gi RWX slow 152m
使用下面的文件创建pod
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 apiVersion: v1 kind: Pod metadata: name: test-pvc-pd spec: containers: - image: nginx name: nginx-volume volumeMounts: - mountPath: /usr/share/nginx/html name: test-volume volumes: - name: test-volume persistentVolumeClaim: claimName: nfs-pvc
此时,使用curl发现403,这是因为挂载的目录中没有文件。在挂载的目录中创建index.html。再次访问发现访问成功。