提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
文章目录
实验目标
进行存储共享实验,使用nfs的技术方案进行跨namespace的存储共享
一、环境准备
- 单点k8s一套:192.168.XX.5
- nfs云主机一台:192.168.XX.62
- nfs目录:192.168.XX.62:/shared/
二、nfs环境的部署及连通性验证
nfs部署链接:https://blog.csdn.net/baidu_35848778/article/details/126933785
在k8s节点(192.168.XX.5)验证nfs-server的连通性
shell
showmount -e 192.168.XX.62
# 输出
Export list for 192.168.XX.62:
/shared 192.168.XX.0/24
三、yaml文件的整理
1. pv文件
testpv1.yaml
yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv1-name
labels:
type: local
spec:
storageClassName: nfs-pv1-sc
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
nfs:
server: 192.168.XX.62
path: /shared/
testpv2.yaml
yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv2-name
labels:
type: local
spec:
storageClassName: nfs-pv2-sc
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
nfs:
server: 192.168.XX.62
path: /shared/
2.pvc文件
pv1-pvc1.yaml
yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: pv1-pvc1
namespace: default
spec:
volumeName: nfs-pv1-name
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
storageClassName: nfs-pv1-sc
pv2-pvc1.yaml
yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: pv2-pvc1
namespace: slw-mariadb
spec:
volumeName: nfs-pv2-name
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
storageClassName: nfs-pv2-sc
3.pod文件
pod1.yaml
yaml
apiVersion: v1
kind: Pod
metadata:
name: minio-1
namespace: default
spec:
containers:
- name: minio
image: minio:RELEASE.2022-12-07T00-56-37Z
env:
- name: MINIO_ACCESS_KEY
value: "admin"
- name: MINIO_SECRET_KEY
value: "admin123456"
- name : TZ
value: Asia/Shanghai
command:
- /bin/bash
- -c
args:
- minio server /data --console-address :9090 --address :9000
# add port for pod
ports:
- containerPort: 9090
name: console-address
- containerPort: 9000
name: address
volumeMounts:
- name: minio-data-one
mountPath: /data
#nodeSelector:
# kubernetes.io/hostname: kubealpha.local
volumes:
- name: minio-data-one
persistentVolumeClaim:
claimName: pv1-pvc1
pod2.yaml
yaml
apiVersion: v1
kind: Pod
metadata:
name: minio-2
namespace: slw-mariadb
spec:
containers:
- name: minio
image: harbor.ictnj.ac.cn:10002/library/minio:RELEASE.2022-12-07T00-56-37Z
env:
- name: MINIO_ACCESS_KEY
value: "admin"
- name: MINIO_SECRET_KEY
value: "admin123456"
- name : TZ
value: Asia/Shanghai
command:
- /bin/bash
- -c
args:
- minio server /data --console-address :9090 --address :9000
# add port for pod
ports:
- containerPort: 9090
name: console-address
- containerPort: 9000
name: address
volumeMounts:
- name: minio-data-one
mountPath: /data
#nodeSelector:
# kubernetes.io/hostname: kubealpha.local
volumes:
- name: minio-data-one
persistentVolumeClaim:
claimName: pv2-pvc1
四、创建资源
1.创建PV
shell
root@node1:/home# kubectl create -f testpv1.yaml
persistentvolume/nfs-pv1-name created
root@node1:/home# kubectl create -f testpv2.yaml
persistentvolume/nfs-pv2-name created
root@node1:/home# kubectl get pv -A
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
nfs-pv1-name 10Gi RWX Retain Available nfs-pv1-sc 6s
nfs-pv2-name 10Gi RWX Retain Available nfs-pv2-sc 3s
2.创建PVC
shell
root@node1:/home# kubectl create -f pv1-pvc1.yaml
persistentvolumeclaim/pv1-pvc1 created
root@node1:/home# kubectl create -f pv2-pvc1.yaml
persistentvolumeclaim/pv2-pvc1 created
root@node1:/home# kubectl get pv -A
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
nfs-pv1-name 10Gi RWX Retain Bound default/pv1-pvc1 nfs-pv1-sc 2m12s
nfs-pv2-name 10Gi RWX Retain Bound slw-mariadb/pv2-pvc1 nfs-pv2-sc 2m9s
3.创建pod
shell
root@node1:/home# kubectl create -f pod1.yaml
pod/minio-1 created
root@node1:/home# kubectl create -f pod2.yaml
pod/minio-2 created
root@node1:/home# kubectl get pod -A |grep minio
default minio-1 1/1 Running 0 41s
slw-mariadb minio-2 1/1 Running 0 38s
五、进行文件创建实验
在pod1中创建文件,在pod2及nfs-client端检查是否可以看到文件