k8s存储实验-使用nfs进行跨命名空间的多pod共享存储

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录


实验目标

进行存储共享实验,使用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端检查是否可以看到文件

1.minio-1中创建测试文件

2.minio-2进行验证

3.nfs-client端验证

相关推荐
csdn_金手指19 分钟前
docker-compose文件的简介及使用
运维·docker·容器
踏雪Vernon1 小时前
[OpenHarmony5.0][Docker][环境]OpenHarmony5.0 Docker pull线上镜像方式构建编译环境
docker·容器·鸿蒙系统
0110编程之路1 小时前
ubuntu20.04安装docker compose
运维·docker·容器
lly_csdn1232 小时前
【Docker】常用命令汇总
linux·运维·docker·容器
努力的Andy3 小时前
修改Docker 默认存储目录( Docker Root Dir: /var/lib/docker)
linux·docker·容器
hai405873 小时前
Docker 启动和停止的精准掌舵:操控指南
docker·容器·eureka
极客先躯4 小时前
k8s 架构详解
容器·架构·kubernetes·etcd·scheduler·api server
云上星空4 小时前
K8s调度器扩展(scheduler)
java·贪心算法·kubernetes
怡雪~4 小时前
K8s的API资源对象NetworkPolicy
linux·容器·kubernetes
Linux运维技术栈4 小时前
自动化运维(k8s)之微服务信息自动抓取:namespaceName、deploymentName等全解析
运维·kubernetes·自动化