hostPath PersistentVolume 和 spec.capacity.storage 属性

hostPath PersistentVolume and spec.capacity.storage attribute

我是 运行 虚拟机中的单个 master/node 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 当前绑定到该卷,请求所有容量 (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 

我的问题是:

根据 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.