赞
踩
pod重启,数据依然存在
(1)安装nfs
yum install -y nfs-utils
(2)设置挂载路径
vi /etc/exports
/data/nfs *(rw,no_root_squash)
(3)设置的挂载路径首先保证有这个路径,没有则创建
mkdir data
mkdir nfs
yum install -y nfs-utils
systemctl start nfs
//查看nfs进程
ps -ef | grep nfs
mkdir pv cd pv vi nfs-nginx.yaml //nfs-nginx.yaml apiVersion: apps/v1 kind: Deployment metadata: name: nginx-dep1 spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx volumeMounts: - name: wwwroot mountPath: /usr/share/nginx/html ports: - containerPort: 80 volumes: - name: wwwroot nfs: server: 192.168.44.134 #nfs服务器ip path: /data/nfs kubectl apply -f nfs-nginx.yaml kubectl describe pod (pod名称) //进入pod kubectl exec -it (pod名称) bash ls /usr/share/nginx/html kubectl expose deployment nginx-dep1 --port=80 --target-port=80 --type=NodePort
PV:持久化存储(生产者)
对存储的资源进行抽象,对外提供可以调用的地方
PVC:持久化存储调用(消费者)
用于调用。不需要关心内部实现的细节
//pvc.yaml apiVersion: apps/v1 kind: Deployment metadata: name: nginx-dep1 spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx volumeMounts: - name: wwwroot mountPath: /usr/share/nginx/html ports: - containerPort: 80 volumes: - name: wwwroot persistentVolumeClaim: claimName: my-pvc --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: my-pvc spec: accessModes: - ReadWriteMany resources: requests: storage: 5Gi kubectl apply -f pvc.yaml
//pv.yaml apiVersion: v1 kind: PersistentVolume metadata: name: my-pv spec: capacity: storage: 5Gi accessModes: - ReadWriteMany nfs: path: /k8s/nfs server: 192.168.44.134 kubectl apply -f pvc.yaml
kubectl get pv,pvc
kubectl get pods
kubectl exec -it pod名称 bash
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。