kubernetes - hostPath PersistentVolume 和 spec.capacity.storage 属性

标签 kubernetes persistent-volumes

我在虚拟机中运行单个主/节点 Kubernetes,使用 hostPath 作为已部署 Postgres 数据库的持久卷。

我的PersistentVolume具有以下配置:

apiVersion: v1
kind: PersistentVolume
metadata:
  annotations:
    volume.beta.kubernetes.io/storage-class: postgres
  labels:
    type: local
  name: postgres-storage
spec:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 1Gi
  hostPath:
    path: /data/postgres

此外,我当前有一个 PersistentVolumeClaim 绑定(bind)到该卷,请求所有容量 (spec.resources.requests.storage: 1Gi )。

最近,Postgres 数据库的大小超出了 spec.capacity.storage,但没有造成任何问题:

$ du -hs /data/postgres # Powers of 1024
1.2G    /data/postgres 

$ du -hs /data/postgres --si # Powers of 1000
1.3G    /data/postgres 

我的问题是:

  • spec.capacity.storage使用 hostPath 时确实很重要 卷,或者该卷实际上由底层分区覆盖 尺寸?
  • 当卷使用量超过其容量时会发生什么? (即 Kubernetes 将如何处理这个问题)

最佳答案

根据 Kubernetes GitHub 页面上的 @wongma7 的说法:

this is working as intended, kube can't/won't enforce the capacity of PVs, the capacity field on PVs is just a label. It's up to the "administrator" i.e. the creator of the PV to label it accurately so that when users create PVCs that needs >= X Gi, they get what they want.

您可以找到原始讨论here .

此外,官方Volume/Resources中也对此进行了介绍。文档:

There is no limit on how much space an emptyDir or hostPath volume can consume, and no isolation between Containers or between Pods.

In the future, we expect that emptyDir and hostPath volumes will be able to request a certain amount of space using a resource specification, and to select the type of media to use, for clusters that have several media types.

关于kubernetes - hostPath PersistentVolume 和 spec.capacity.storage 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55619425/

相关文章:

kubernetes - 我可以使用 GCP HTTPS 负载均衡器在存储桶后端和 Kubernetes 服务之间进行路由吗?

azure - 托管 Azure Kubernetes 连接错误

wordpress - 如何在Kubernetes集群中扩展Wordpress-使用多个Pod副本-访问单个PVC(永久文件存储)

kubernetes - HostPath 将 persistentVolume 分配给集群中的特定工作节点

kubernetes - 如何更改现有持久卷的存储类?

kubernetes - kustomize 编辑集图像不适用于 kustomize multibases 和 common base

Mysql 容器无法在 Kubernetes 上启动

azure - 如何配置手动预配的 Azure 托管磁盘以用作 Kubernetes 持久卷?

Kubernetes 持久卷 : MountPath directory created but empty

kubernetes - PersistentVolumeClaim 未绑定(bind) : "nfs-pv-provisioning-demo"