通过storageClassName 将PV 和PVC 关联起来。
[root@k8-master home]# cat /home/npm-pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:name: npm-repository-pvcnamespace: jenkins
spec:accessModes:- ReadWriteManyresources:requests:storage: 50GistorageClassName: npm-repository-pv
[root@k8-master yaml]# cat /home/npm-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:name: npm-repository-pv
spec:capacity:storage: 50GiaccessModes:- ReadWriteManystorageClassName: "npm-repository-pv"nfs:server: 192.168.10.128path: /data/repository/npm
[root@k8-master yaml]# cat nginx-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:name: nginx-k8s-pv
spec:capacity:storage: 10GiaccessModes:- ReadWriteManystorageClassName: "nginx-k8s-pv"nfs:server: 192.168.10.128path: /data/volumes
[root@k8-master yaml]# cat nginx-pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:name: nginx-k8s-pvcnamespace: test
spec:resources:requests:storage: 10GiaccessModes:- ReadWriteManystorageClassName: "nginx-k8s-pv"
[root@k8-master yaml]# cat nginx.yaml
apiVersion: apps/v1
kind: Deployment
metadata:name: nginx-deploynamespace: test
spec:selector: matchLabels: app: nginx replicas: 1 template: metadata: labels: app : nginx spec: containers:- image: nginx:1.21name: nginxports: - containerPort: 80 protocol: TCP volumeMounts: - name: nfs-volumes mountPath: /usr/share/nginx/html- name: nginx-configmountPath: /etc/nginx/nginx.confsubPath: nginx.confvolumes: - name: nfs-volumespersistentVolumeClaim:claimName: nginx-k8s-pvc - name: nginx-config configMap:name: nginx-configitems:- key: nginx.confpath: nginx.conf