💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
NFS 的使用步骤如下: **1. 找一台机器作为 NFS 服务器** ```shell 【1】安装 NFS # yum -y install nfs-utils 【2】启动 NFS 服务 # systemctl start nfs # ps -ef | grep nfs root 26919 2 0 22:39 ? 00:00:00 [nfsd4_callbacks] root 26925 2 0 22:39 ? 00:00:00 [nfsd] root 26926 2 0 22:39 ? 00:00:00 [nfsd] root 26927 2 0 22:39 ? 00:00:00 [nfsd] root 26928 2 0 22:39 ? 00:00:00 [nfsd] root 26929 2 0 22:39 ? 00:00:00 [nfsd] root 26930 2 0 22:39 ? 00:00:00 [nfsd] root 26931 2 0 22:39 ? 00:00:00 [nfsd] root 26932 2 0 22:39 ? 00:00:00 [nfsd] root 27271 24077 0 22:40 pts/1 00:00:00 grep --color=auto nfs 【3】nfs 开机自启 # systemctl enable nfs-server # systemctl enable rpcbind 【4】添加一个 NFS 挂载路径 # vim /etc/exports /home/cone/share 【5】需要手动创建挂载路径 # mkdir -p /home/cone/share 【6】让配置生效 # exportfs -r ``` <br/> **2. 在 k8s 集群所有的 node 节点安装 NFS** >[info]master 节点不需要安装。 ```shell # yum -y install nfs-utils ``` <br/> **3. 部署一个应用来演示 NFS 存储的调用** ```shell 【1】 # kubectl create deployment nginx-dep01 --image=nginx:latest --dry-run=client -o yaml > nginx-dep01.yaml 【2】 # vim nginx-dep01.yaml apiVersion: apps/v1 kind: Deployment metadata: labels: app: nginx-dep01 name: nginx-dep01 spec: replicas: 1 selector: matchLabels: app: nginx-dep01 template: metadata: labels: app: nginx-dep01 spec: containers: - image: nginx:latest name: nginx volumeMounts: - name: share-nginx #这个是nginx默认的目录 mountPath: /usr/share/nginx/html volumes: - name: share-nginx nfs: #nfs服务器ip server: 192.168.1.16 #nfs服务器的挂载目录 path: /home/cone/share ``` ![](https://img.kancloud.cn/1c/b3/1cb3a8a4aa5b38e3ef59a9fe7ce924ff_2020x519.png) <br/> ```shell 【3】 # kubectl apply -f nginx-dep01.yaml # kubectl get pods NAME READY STATUS RESTARTS AGE nginx-dep01-7ffcdf5865-pnm4b 1/1 Running 0 16m 【4】进入容器内 # kubectl exec -it nginx-dep01-7ffcdf5865-pnm4b bash root@nginx-dep01-7ffcdf5865-pnm4b:/# root@nginx-dep01-7ffcdf5865-pnm4b:/# cd /usr/share/nginx/html root@nginx-dep01-7ffcdf5865-pnm4b:/# ls /* 这个时候该目录下什么都还没有 */ 【5】在 nfs 服务器的挂载目录下随便创建一个文件 # cd /home/cone/share # vim index.html Hello World! 【6】再看 Pod 容器内就可以看到创建的文件了 root@nginx-dep01-7ffcdf5865-pnm4b:/# ls index.html root@nginx-dep01-7ffcdf5865-pnm4b:/# cat index.html Hello World! ``` <br/> **4. 至此,说明已经可以将容器内的数据持久化到 NFS 服务器了** **** 参考文档:https://feisky.xyz/kubernetes-handbook/concepts/volume.html