nfs远端存储
1. 部署nfs
yum -y install nfs-utils
yum -y install rpcbind
systemctl restart rpcbind && systemctl restart nfs-server
2. 创建挂载目录
mkdir /data/v{1,2}
3. 共享挂载目录
cat /etc/exports
/data/v1 192.168.217.0/24(rw,no_root_squash)
/data/v2 192.168.217.0/24(rw,no_root_squash)
4. 刷新配置
exportfs -rv
showmount -e
5. 创建pv
vim pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv01
labels:
name: pv01
spec:
nfs:
path: /data/v2/
server: 192.168.217.128
accessModes: ["ReadWriteOnce","ReadWriteMany"]
capacity:
storage: 5Gi
kubectl apply -f pv.yaml
6. 创建pvc
vim pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mypvc
spec:
accessModes: ["ReadWriteMany"]
resources:
requests:
storage: 5Gi
kubectl apply -f pvc.yaml
查看挂载情况
kubectl get pv
pv02 5Gi RWO,RW Retain Bound default/mypvc 4h
7. 部署测试pod
vim deploymeny.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-volume-pvc
namespace: default
spec:
containers:
- name: nginx-pvc
image: daocloud.io/library/nginx:1.16.0-alpine-perl
ports:
- containerPort: 80
volumeMounts:
- name: html
mountPath: /usr/share/nginx/html/
volumes:
- name: html
persistentVolumeClaim:
claimName: mypvc