K8S Strore1:Deployment使用NFS进行挂载

K8S Strore1:Deployment使用NFS进行挂载

1. 原生方式数据挂载

1.1 创建文件

# 1. 创建文件 root@docker01:/home# vim deploy-nfs.yaml
  • server是主节点ip
apiVersion: apps/v1 kind: Deployment metadata: labels: app: nginx-pv name: nginx-pv spec: replicas: 2 selector: matchLabels: app: nginx-pv template: metadata: labels: app: nginx-pv spec: containers: - image: nginx name: nginx volumeMounts: - name: html mountPath: /usr/share/nginx/html volumes: - name: html nfs: server: 192.168.92.138 path: /nfs/data/nginx-pv
 

1.2 运行

# 2, 运行文件,创建pods kubectl apply -f deploy-nfs.yaml # 3. 查看 root@docker01:/home# kubectl get pod
notion image
一直没启动,查看pod的详细信息

1.2.1 排错

 
方法一:使用命令
root@docker01:/home# kubectl describe pod nginx-pv-577f88bf5d-hnmkh
notion image
  • 最后显现,没有该目录,创建即可
方法二:查看dashboard可视化界面,找到对应的pod点击查看
notion image
  • 发现是没有目录,创建即可
 

1.2.2 解决

创建文件
root@docker01:/home# cd /nfs/data/ root@docker01:/nfs/data# ls a root@docker01:/nfs/data# mkdir -p nginx-pv root@docker01:/nfs/data# ls a nginx-pv root@docker01:/nfs/data#
删除刚刚的deploy
root@docker01:/nfs/data# kubectl get deploy NAME READY UP-TO-DATE AVAILABLE AGE hello-server 2/2 2 2 20h my-dep 3/3 3 3 45h my-tomcat 1/1 1 1 26h nginx-demo 2/2 2 2 20h nginx-pv 0/2 2 0 9m32s root@docker01:/nfs/data# cd /home/ root@docker01:/home# ls calico.yaml deploy.yaml hello.yaml ingress-rule-2.yaml nginx.conf dashboard-admin.yml docker01 images.sh ingress-rule.yaml pod.yaml deploy-nfs.yaml hello_world.tar ingress_domain.yaml multicontainer-pod.yaml test.txt root@docker01:/home# kubectl delete -f deploy-nfs.yaml deployment.apps "nginx-pv" deleted root@docker01:/home# kubectl apply -f deploy-nfs.yaml deployment.apps/nginx-pv created
过一会儿即可创建成功了,如图
notion image

2. 测试

2.1 创建文件

  • 在docker01中/nfs/data/ nginx-pv/创建文件
root@docker01:/home# cd /nfs/data/ root@docker01:/nfs/data# ls a nginx-pv root@docker01:/nfs/data# cd nginx-pv/ root@docker01:/nfs/data/nginx-pv# ls root@docker01:/nfs/data/nginx-pv# echo "Hello,NFS!" > index.html root@docker01:/nfs/data/nginx-pv#
 

2.2 在Pod中查看

notion image
 
notion image
 

3. 存在弊端

  1. 文件夹需要自己创建
  1. 删除这次部署,文件内容仍然存在,不会自动清理
  1. 文件使用空间没有限制