我在虚拟机中运行单个主/节点 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
orhostPath
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/