hostPath volume存在的问题有哪些

发布时间:2021-12-20 09:49:09 作者:iii
来源:亿速云 阅读:301

本篇内容介绍了“hostPath volume存在的问题有哪些”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

hostPath volume存在的问题

过去我们经常会通过hostPath volume让Pod能够使用本地存储,将Node文件系统中的文件或者目录挂载到容器内,但是hostPath volume的使用是很难受的,并不适合在生产环境中使用。

我们先看看hostPath Type有哪些类型:

ValueBehavior

Empty string (default) is for backward compatibility, which means that no checks will be performed before mounting the hostPath volume.
DirectoryOrCreateIf nothing exists at the given path, an empty directory will be created there as needed with permission set to 0755, having the same group and ownership with Kubelet.
DirectoryA directory must exist at the given path
FileOrCreateIf nothing exists at the given path, an empty file will be created there as needed with permission set to 0644, having the same group and ownership with Kubelet.
FileA file must exist at the given path
SocketA UNIX socket must exist at the given path
CharDeviceA character device must exist at the given path
BlockDeviceA block device must exist at the given path

看起来支持这么多type还是挺好的,但为什么说不适合在生产环境中使用呢?

local persistent volume工作机制

FEATURE STATE: Kubernetes v1.11 Beta

Local persistent volume就是用来解决hostPath volume面临的**portability, disk accounting, and scheduling**的缺陷。PV Controller和Scheduler会对local PV做特殊的逻辑处理,以实现Pod使用本地存储时发生Pod re-schedule的情况下能再次调度到local volume所在的Node。

local pv在生产中使用,也是需要谨慎的,毕竟它本质上还是使用的是节点上的本地存储,如果没有相应的存储副本机制,那意味着一旦节点或者磁盘异常,使用该volume的Pod也会异常,甚至出现数据丢失,除非你明确知道这个风险不会对你的应用造成很大影响或者允许数据丢失。

那么通常什么情况会使用Local PV呢?

Local volume允许挂载本地的disk, partition, directory到容器内某个挂载点。在Kuberentes 1.11仍然仅支持local pv的static provision,不支持dynamic provision。

下面是定义local pv的Sample:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: example-pv
spec:
  capacity:
    storage: 100Gi
  # volumeMode field requires BlockVolume Alpha feature gate to be enabled.
  volumeMode: Filesystem
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: local-storage
  local:
    path: /mnt/disks/ssd1
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - example-node

对应的local-storage storageClass定义如下:

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer

使用local persistent volume注意事项

local volume manager

上面这么多事情需要人为的去做预处理的工作,我们必须要有解决方案帮我们自动完成local volume的create和cleanup的工作。官方给出了一个简单的local volume manager,注意它仍然只是一个static provisioner,目前主要帮我们做两件事:

因此,除了需要人为的完成local volume的mount操作,local PV的生命周期管理就全部交给local volume manager了。下面我们专门介绍下这个Static Local Volume Provisioner。

“hostPath volume存在的问题有哪些”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

推荐阅读:
  1. docker volume源码的示例分析
  2. glusterfs volume管理相关问题有哪些

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

hostpath volume

上一篇:如何实现基于Bash Shell的一个审计脚本

下一篇:如何使用脚本下载风云卫星数据所有订单

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》