k8s安装nfs共享存储卷
时间: 2023-10-19 21:09:03 浏览: 170
在k8s中安装NFS共享存储卷的步骤如下:
1. 在k8s集群的每个节点上安装NFS客户端依赖:
`sudo apt-get install nfs-common`
2. 配置NFS服务器,可以在一台独立的虚拟机上进行配置。安装NFS服务器并设置挂载路径:
```
sudo apt-get install nfs-kernel-server
sudo mkdir /data/nfs
sudo vi /etc/exports # 添加如下内容
/data/nfs *(rw,sync,no_subtree_check)
sudo exportfs -a
sudo systemctl restart nfs-kernel-server
```
3. 创建一个PersistentVolume和PersistentVolumeClaim来定义NFS存储:
```yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
nfs:
server: <NFS服务器IP地址>
path: /data/nfs
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nfs-pvc
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi
```
4. 创建一个Pod来使用NFS存储:
```yaml
apiVersion: v1
kind: Pod
metadata:
name: nfs-pod
spec:
containers:
- name: nfs-container
image: <容器镜像>
volumeMounts:
- name: nfs-volume
mountPath: /data
volumes:
- name: nfs-volume
persistentVolumeClaim:
claimName: nfs-pvc
```
阅读全文