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 存储时,定义如下:

[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。
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 @ 2022-06-23 17:48  左扬  阅读(76)  评论(0编辑  收藏  举报
levels of contents