1.创建nfs的pod
cat > nfs-server-pod.yaml <<"EOF"
apiVersion: v1
kind: Pod
metadata:
name: nfs-server
labels:
role: nfs-server
spec:
containers:
- name: nfs-server
image: jsafrane/nfs-data:latest
ports:
- name: nfs
containerPort: 2049
securityContext:
privileged: true
EOF
2.创建nfs的service
cat > nfs-service.yaml <<"EOF"
kind: Service
apiVersion: v1
metadata:
name: nfs-server
spec:
clusterIP: 10.254.234.223
ports:
- port: 2049
selector:
role: nfs-server
EOF
3.使用
apiVersion: v1
kind: Pod
metadata:
name: nfs-web
spec:
containers:
- name: my-nginx
image: nginx:1.7.9
ports:
- name: nfs
containerPort: 80
volumeMounts:
# name must match the volume name below
- name: nfs
mountPath: "/usr/share/nginx/html"
volumes:
- name: nfs
nfs:
# FIXME: use the right hostname
server: 10.254.234.223
path: "/"
4.配置nfs
a.安装
#在k8s的master安装
yum install -y nfs-utils rpcbind
#在每个node安装
yum install -y nfs-utils
b.启动及查看状态
systemctl start rpcbind
systemctl status rpcbind
systemctl start nfs
systemctl status nfs
c.配置文件
#NFS服务的配置文件 /etc/exports
vim /etc/exports加入以下配置 ip段根据kubectl get svc查询nfs-server的ip决定10.254.234.223
/nfs/prometheus/data/ 10.254.234.0/24(rw,no_root_squash,no_all_squash,sync)
d.创建文件并授权
#exports中的配置的内容,需要创建下/nfs/prometheus/data/
mkdir -p /nfs/prometheus/data/
#修改权限
chmod -R 777 /nfs/prometheus/data/
e.验证
#验证配置的/nfs/prometheus/data/是否正确
exportfs -r
查看
showmount -e 10.254.234.223
输出
Export list for 10.254.234.223:
/nfs/prometheus/data 10.254.234.0/24
https://blog.youkuaiyun.com/shenhonglei1234/article/details/80827570
https://www.cnblogs.com/zihanxing/articles/6004202.html
https://www.cnblogs.com/liuyansheng/p/6108952.html