Kubernetes——网络存储卷

网络存储卷

  Kubernetes 拥有众多类型的用于适配专用存储系统的网络存储卷。这类存储卷包括传统的 NAS 或 SAN 设备(如 NFS、iSCSI、fc)、分布式存储(如 GlusterFS、RBD)、云端存储(如 gcePersistentDisk、azureDisk、cinder 和 awsElasticBlockStore)以及建构在各类存储系统之上的抽象管理层(如 flocker、portworxVolume 和 vsphereVolume)等。

一、NFS存储卷

  NFS 即网络文件系统(Network File System),它是一种分布式文件系统协议,最初是由 Sun MicroSystems 公司开发的类 Unix 操作系统之上的一款经典的网络存储方案,其功能旨在允许客户端主机可以像访问本地存储一样通过网络访问服务器端的文件。

  Kubernetes 的 NFS 存储卷用于将实现存在 NFS 服务器上导出(export)的存储空间挂载到 Pod 中以供容器使用。与 emptyDir 不同的是,NFS 存储卷在 Pod 对象终止后仅是被卸载而非删除。

  NFS 是文件系统级共享服务,它支持同时存在的多路挂载请求。定义 NFS 存储时,定义如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[root@mh-k8s-master-247-10 ~]# kubectl explain pod.spec.volumes.nfs
KIND:     Pod
VERSION:  v1
 
RESOURCE: nfs <Object>
 
DESCRIPTION:
     NFS represents an NFS mount on the host that shares a pod's lifetime More
     info: https://kubernetes.io/docs/concepts/storage/volumes#nfs
 
     Represents an NFS mount that lasts the lifetime of a pod. NFS volumes do
     not support ownership management or SELinux relabeling.
 
FIELDS:
   path <string> -required-
     Path that is exported by the NFS server. More info:
     https://kubernetes.io/docs/concepts/storage/volumes#nfs
 
   readOnly <boolean>
     ReadOnly here will force the NFS export to be mounted with read-only
     permissions. Defaults to false. More info:
     https://kubernetes.io/docs/concepts/storage/volumes#nfs
 
   server   <string> -required-
     Server is the hostname or IP address of the NFS server. More info:
     https://kubernetes.io/docs/concepts/storage/volumes#nfs
 
[root@mh-k8s-master-247-10 ~]#

  常用到以下字段:

  • server <string> -required-:NFS 服务器的 IP 地址或主机名,必选字段。
  • path <string> -required-:NFS 服务器导出(共享)的文件系统路径,必选字段。
  • readOnly <boolean>:是否以只读方式挂载,默认为 false。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
apiVersion: v1
kind: Pod
metadata:
  name: vol-nfs-pod
  labels:
    app: redis
spec:
  containers:
  - name: redis
    image: redis:4-alpine
    ports:
    - containerPort: 6379
      name: redisport
    volumeMounts:
    - mountPath: /data
      name: redisdata
  volumes:
  - name: redisdata
    nfs:
      server: nfs.xxx.com
      path: /data/redis
      readOnly: false

  上面的示例定义在资源配置文件 vol-nfs.yaml 中,其中的 Pod 资源拥有一个关联至 NFS 服务器 nfs.xxx.com 的存储卷,Redis 容器将其挂载于 /data 目录上,它是运行于容器中的 redis-server 数据的持久保存位置。

posted @   左扬  阅读(86)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2021-06-23 Jenkins从入门到精通——SonarQube:持续代码质量检查
2021-06-23 Jenkins从入门到精通——代码质量
levels of contents
点击右上角即可分享
微信分享提示