nfs服务器创建可看上一篇文章
https://blog.csdn.net/weixin_43205308/article/details/129656888
1、创建pvc
vim my-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi
kubectl apply -f my-pvc.yaml
2、创建关于pvc的nginx
vim nginx-pvc.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-pvc
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: nginx
name: nginx
volumeMounts:
- name: wwwroot
mountPath: /user/share/nginx/html #挂载容器的路径
ports:
- containerPort: 80
volumes:
- name: wwwroot
persistentVolumeClaim:
claimName: my-pvc #挂载的pvc名称
kubectl apply -f nginx-pvc.yaml
3、创建pv
vim my-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: my-pv
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteMany
nfs:
path: /data/nfs
server: 192.168.102.49
kubectl apply -f my-pv.yaml
4、查看是否绑定
kubectl get pv,pvc
容器与nfs的/data/nfs内容一致则证明挂载成功
概念