k8s 1.23 nfs动态存储nfs-subdir4.0.18

参考 https://blog.csdn.net/m0_51510236/article/details/132641343

 

nfs服务器:192.168.18.12

master:192.168.18.11

 

nfs动态存储只能应用在一个namespace,其他namespace可以自定义pv

1、在nfs服务器安装nfs

yum install nfs-utils -y
vim /etc/exports
/data/nfs/data1G *(rw,no_root_squash,no_all_squash,sync)
/data/nfs/data2G *(rw,no_root_squash,no_all_squash,sync)
/data/nfs/data3G *(rw,no_root_squash,no_all_squash,sync)
/data/nfs/data4G *(rw,no_root_squash,no_all_squash,sync)
systemctl start nfs && systemctl enable nfs
exportfs -rv

在别的服务器验证nfs

 

以下步骤在master操作

2、下载nfs-subdir源码包,github地址 https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner/releases

wget https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner/archive/refs/tags/nfs-subdir-external-provisioner-4.0.18.tar.gz

3、解压

tar -zxvf nfs-subdir-external-provisioner-4.0.18.tar.gz

4、需要修改的就是 deployment.yaml ,修改镜像仓库地址为   registry.cn-shenzhen.aliyuncs.com/xiaohh-docker/nfs-subdir-external-provisioner:v4.0.2

cd nfs-subdir-external-provisioner-nfs-subdir-external-provisioner-4.0.18
vim deploy/deployment.yaml

 5、修改一下deployment.yaml的nfs服务器地址和nfs服务器内共享的目录:

 6、安装动态供给,直接执行 kubectl apply -k . 安装。可以看到生成了nfs-client的pod和storageclass,因为源码目录里的class.yml定义了storageclass,deployment.yaml定义了pod。

 

7、可以执行下面这个行命令查看是否部署完成:

8、编写yaml验证nfs动态存储

复制代码
vim  pod-exam.yaml

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: test-claim
spec:
  storageClassName: "nfs-client"
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 1Gi
---
apiVersion: v1
kind: Pod
metadata:
  name: test-pod
spec:
  containers:
  - name: test-pod
    image:  nginx
    volumeMounts:
    - name: nfs-pvc
      mountPath: "/usr/share/nginx/html"
  volumes:
  - name: nfs-pvc
    persistentVolumeClaim:
      claimName: test-claim
复制代码

 

9、运行kubectl  apply  -f  pod-exam.yaml 后到nfs服务器的挂载目录看看,查看pv和pvc

 

 

10、进入用到pvc的pod容器里面创建文件,发现nfs挂载目录也有这个文件。验证完成。

 

 

posted @   苦逼yw  阅读(207)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示