PV PVC存储大小设置

huangapple go评论53阅读模式
英文:

PV PVC storage size settings

问题

我正在尝试理解这些设置的作用。
PV - spec.capacity.storage
PVC - spec.resources.requests.storage

我试图限制可以由Pod消耗的存储空间的数量,即固定大小。这两个设置都采用类似于 "10G" 的设置。到目前为止,我尝试的一切似乎都不会强加限制。

有人能解释这些设置或如何限制使用的存储空间吗?

谢谢。

apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv
spec:
capacity:
storage: 10Gi
volumeMode: Filesystem
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Recycle
storageClassName: nfs
mountOptions:
- hard
- nfsvers=4.1
nfs:
path: /mnt/Storage/nfs-test
server: ip_address

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nfs-pvc
spec:
storageClassName: nfs
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi

apiVersion: v1
kind: Pod
metadata:
name: nginx-pv-pod
spec:
volumes:
- name: nginx-pv-storage
persistentVolumeClaim:
claimName: nfs-pvc
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
name: "nginx-server"
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: nginx-pv-storage

$ kubectl describe pv nfs-pv
Name: nfs-pv
Labels:
Annotations: pv.kubernetes.io/bound-by-controller: yes
Finalizers: [kubernetes.io/pv-protection]
StorageClass: nfs
Status: Bound
Claim: default/nfs-pvc
Reclaim Policy: Recycle
Access Modes: RWX
VolumeMode: Filesystem
Capacity: 10Gi
Node Affinity:
Message:
Source:
Type: NFS (an NFS mount that lasts the lifetime of a pod)
Server: ip_address
Path: /mnt/Storage/nfs-test
ReadOnly: false
Events:

$ kubectl describe pvc nfs-pvc
Name: nfs-pvc
Namespace: default
StorageClass: nfs
Status: Bound
Volume: nfs-pv
Labels:
Annotations: pv.kubernetes.io/bind-completed: yes
pv.kubernetes.io/bound-by-controller: yes
Finalizers: [kubernetes.io/pvc-protection]
Capacity: 10Gi
Access Modes: RWX
VolumeMode: Filesystem
Used By: nginx-pv-pod
Events:

所以我猜 "capacity" 设置似乎没有明显的作用。

英文:

I am trying to understand what these settings do.<br>
PV - spec.capacity.storage<br>
PVC - spec.resources.requests.storage

I am trying to limit the amount of storage space that can be consumed by a pod i.e. a fixed size. Both of these settings take a setting like "10G". Everything I have tried so far does not appear to impose a limit.

Can someone explain these settings or how I can limit the storage space used?

Thanks.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs-pv
spec:
  capacity:
    storage: 10Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Recycle
  storageClassName: nfs
  mountOptions:
    - hard
    - nfsvers=4.1
  nfs:
    path: /mnt/Storage/nfs-test
    server: ip_address
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nfs-pvc
spec:
  storageClassName: nfs
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 10Gi
---
apiVersion: v1
kind: Pod
metadata:
  name: nginx-pv-pod
spec:
  volumes:
    - name: nginx-pv-storage
      persistentVolumeClaim:
        claimName: nfs-pvc
  containers:
    - name: nginx
      image: nginx
      ports:
        - containerPort: 80
          name: &quot;nginx-server&quot;
      volumeMounts:
        - mountPath: &quot;/usr/share/nginx/html&quot;
          name: nginx-pv-storage

$ kubectl describe pv nfs-pv
Name:            nfs-pv
Labels:          &lt;none&gt;
Annotations:     pv.kubernetes.io/bound-by-controller: yes
Finalizers:      [kubernetes.io/pv-protection]
StorageClass:    nfs
Status:          Bound
Claim:           default/nfs-pvc
Reclaim Policy:  Recycle
Access Modes:    RWX
VolumeMode:      Filesystem
Capacity:        10Gi
Node Affinity:   &lt;none&gt;
Message:
Source:
    Type:      NFS (an NFS mount that lasts the lifetime of a pod)
    Server:    ip_address
    Path:      /mnt/Storage/nfs-test
    ReadOnly:  false
Events:        &lt;none&gt;

$ kubectl describe pvc nfs-pvc
Name:          nfs-pvc
Namespace:     default
StorageClass:  nfs
Status:        Bound
Volume:        nfs-pv
Labels:        &lt;none&gt;
Annotations:   pv.kubernetes.io/bind-completed: yes
               pv.kubernetes.io/bound-by-controller: yes
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:      10Gi
Access Modes:  RWX
VolumeMode:    Filesystem
Used By:       nginx-pv-pod
Events:        &lt;none&gt;

So I am guessing the "capacity" setting does nothing recognizable.

答案1

得分: 1

我正在尝试限制可以被 Pod 消耗的存储空间数量。

基本上有三个方面需要考虑。一是镜像本身的大小;无法限制这个。二是挂载到容器中的卷;这例如是您显示的 PersistentVolume,并且类似地,您可以将其视为插入一个外部 USB 磁盘,它不会 "计入" 您的内部硬盘存储空间。三是容器进程在运行时使用的磁盘空间,用于临时文件或磁盘日志等。

当您说 "限制容器的存储空间" 时,我认为是指第三个选项。Kubernetes 称之为临时存储,您可以像内存和 CPU 一样为其分配资源限制:

apiVersion: v1
kind: Pod
spec:
  containers:
    - name: nginx
      resources:
        limits:
          ephemeral-storage: 10Gi

对于您展示的示例,您可能不需要额外的卷。将内容复制到卷中并从卷中复制内容可能有点棘手,因此通常不希望使用卷来隐藏镜像中的 HTML 内容等。

更典型的示例可能是数据库容器。您需要为数据库数据本身提供持久存储,这样它可以跟随数据库 Pod 在集群中删除和重新创建。典型的步骤如下:

  1. 运营商创建一个 StatefulSet 来运行数据库。
  2. Kubernetes 从 StatefulSet 模板为每个副本创建 PersistentVolumeClaim,包括 PVC 请求的 storage 大小。
  3. 作为集群基础设施运行的 持久卷供应商 获取适当的存储(例如 AWS EBS 卷),并将其详细信息记录在 PersistentVolume 中。

因此,通过这种流程,您不直接创建 PersistentVolume;相反,在创建 PersistentVolumeClaim 时,您指定了您希望该存储的大小。

您的设置使用 NFS 作为存储后端。如果您有 NFS 服务器,那就没问题,但是 PersistentVolume/Claim 中的元数据并不意味着 NFS 后端上的任何磁盘配额。PVC 请求至少有 10 GiB 的存储可用,并且 PV 声明它存在,但实际上,您可能可以使用 NFS 服务器的整个磁盘,不管它有多大。

英文:

> I am trying to limit the amount of storage space that can be consumed by a pod

There's essentially three things here. One is the size of the image itself; there's no way to limit this. A second is volumes you mount into the container; this is for example the PersistentVolume you show, and by analogy you might think of it like plugging in an external USB disk that doesn't "count against" your internal hard drive storage. The third is disk space used up by the container process while it's running, for things like temporary files or on-disk logs.

When you say "limit the storage space of a container" I think of that third option. Kubernetes calls this ephemeral storage and you can assign resource limits to it the same way you can memory and CPU:

apiVersion: v1
kind: Pod
spec:
  containers:
    - name: nginx
      resources:
        limits:
          ephemeral-storage: 10Gi

For the example you show, you probably do not need an additional volume. It can be a little tricky to copy content in and out of a volume, so you don't usually want to use a volume to hide things like the HTML content in an image.

A more typical example of these would be a database container. You want persistent storage for the database data itself, that's capable of following the database pod around the cluster if it gets deleted and recreated. A typical sequence there is

  1. The operator creates a StatefulSet to run the database
  2. Kubernetes creates a PersistentVolumeClaim for each replica from the template in the StatefulSet, including the PVC's requested storage size
  3. A persistent volume provisioner running as cluster infrastructure gets appropriate storage (for example, an AWS EBS volume) and records its details in a PersistentVolume

So with this flow you don't directly create the PersistentVolume; but conversely you do specify the size you want that storage to be when you create the PersistentVolumeClaim.

Your setup uses NFS as a storage backend. That's fine if you have an NFS server, but the metadata in the PersistentVolume/Claim doesn't imply any sort of disk quota on the NFS backend. The PVC requests that at least 10 GiB of storage is available and the PV asserts it's there, but in reality you can probably use the full disk of the NFS server, however large it is.

答案2

得分: 0

以下是翻译好的部分:

持久卷(PV)允许Kubernetes分配一部分磁盘空间,然后可以由持久卷索赔(全部或部分)。如果您创建一个大小为10GB的PV,您可以从该PV索赔多达10GB的空间。只要PVC的总和等于PV的大小或小于PV的大小,就可以有多个PVC索赔PV中的空间。如果尝试创建一个大于PV大小的PVC,则PVC索赔将失败,使用PVC的Pod将标记为“待处理”。

创建一个10GB的PV只限制了PVC的索赔。如果创建PVC并将其挂载到Pod中,那么Pod仍然可以拥有大于10GB的文件。事实上,PVC中没有文件大小限制!

英文:

What I have gleaned and learned:

A PersistentVolume (PV) allows Kubernetes to allocate a section of disk space that can then be claimed (all or part) by a PersistentVolumeClaim. If you create a PV of say 10GB, you can claim up to 10GBs of space from that PV. You can have multiple PVCs claim space in a PV as long as the sum total of the PVCs are the same or less that the size of the PV. If you try to create a PVC that is more that the size of the PV, the PVC claim will fail and the pods that use the PVC will be marked "Pending".

Creating a PV of 10GB only limits the claims of the PVCs. If you create a PVC and mount it into a pod, the pod can still have file(s) of greater that 10GB. In fact there is no file size limit in the PVC!

huangapple
  • 本文由 发表于 2023年7月20日 19:44:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76729508.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定