> ## Content Index
> Fetch the complete content index at: https://lucent.blog/llms.txt
> Use this file to discover other available public pages before exploring further.

# 搭建NFS为K8s集群提供存储服务
- URL: https://lucent.blog/da-jian-nfs/
- Published: 2021-11-17T07:12:25.000Z
- Updated: 2026-08-21T00:49:56.000Z
- Author: Lucent

### 说明

由于使用k8s部署应用时，大部分情况下无需指定部署到哪个节点（服务器），这时如果应用程序需要访问本地文件，就可能会出错，因为并不是因为每个节点都有相应文件，即使有，也不一定完全相同，所以这时就需要利用k8s的PVC来实现了。PVC 是用户存储的一种声明，对于真正使用存储的用户不需要关心底层的存储实现细节，只需要直接使用 PVC 即可。

**使用PVC需要NFS，所以我们需要在某台服务器上搭建NFS来为集群提供存储服务**

### 搭建命令

```shell
yum install -y nfs-common nfs-utils  rpcbind 
#创建本地文件夹并分配权限
mkdir /nfsdata  && chmod 666 /nfsdata && chown nfsnobody /nfsdata
# 配置挂载
vi /etc/exports
# 写入以下内容
/nfsdata *(rw,no_root_squash,no_all_squash,sync)
# 启动
systemctl start rpcbind && systemctl start nfs

```