持久卷挂载远大于容量.存储属性

问题描述 投票:0回答:1

最近我发现我的磁盘空间不足。
我检查了磁盘使用情况,发现我的 Postgres 数据库消耗了 375GB,但是我的持久卷存储仅设置为 5GB。

我检查了PV和PVC:

Name:          postgres-volume-claim
Namespace:     default
StorageClass:  local-storage
Status:        Bound
Volume:        postgres-volume
Labels:        app=postgres
Annotations:   pv.kubernetes.io/bind-completed: yes
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:      5Gi
Access Modes:  RWX
VolumeMode:    Filesystem
Used By:       postgres-8475b9554f-czjq8
Events:        <none>
Name:            postgres-volume
Labels:          app=postgres
Annotations:     pv.kubernetes.io/bound-by-controller: yes
Finalizers:      [kubernetes.io/pv-protection]
StorageClass:    local-storage
Status:          Bound
Claim:           default/postgres-volume-claim
Reclaim Policy:  Retain
Access Modes:    RWX
VolumeMode:      Filesystem
Capacity:        5Gi
Node Affinity:   <none>
Message:         
Source:
    Type:          HostPath (bare host directory volume)
    Path:          /mnt/raid/db
    HostPathType:  
Events:            <none>

以及挂载目录的磁盘使用情况:

4,0K    db/pgdata/pg_twophase
4,0K    db/pgdata/pg_stat
832K    db/pgdata/pg_subtrans
4,0K    db/pgdata/pg_wal/archive_status
7,5G    db/pgdata/pg_wal
4,0K    db/pgdata/pg_snapshots
592K    db/pgdata/global
4,0K    db/pgdata/pg_serial
4,0K    db/pgdata/pg_replslot
4,0K    db/pgdata/pg_tblspc
12K db/pgdata/pg_multixact/members
12K db/pgdata/pg_multixact/offsets
28K db/pgdata/pg_multixact
12K db/pgdata/pg_notify
161G    db/pgdata/base/16476
7,6G    db/pgdata/base/pgsql_tmp
199G    db/pgdata/base/16477
7,4M    db/pgdata/base/1
7,9M    db/pgdata/base/452050895
7,6M    db/pgdata/base/13067
7,4M    db/pgdata/base/13066
8,6M    db/pgdata/base/30664
367G    db/pgdata/base
5,6M    db/pgdata/pg_xact
4,0K    db/pgdata/pg_dynshmem
4,0K    db/pgdata/pg_logical/snapshots
4,0K    db/pgdata/pg_logical/mappings
16K db/pgdata/pg_logical
116K    db/pgdata/pg_stat_tmp
4,0K    db/pgdata/pg_commit_ts
374G    db/pgdata
374G    db

持久卷的挂载目录怎么可能比5Gi大很多?

postgresql kubernetes persistent-volumes persistent-volume-claims
1个回答
0
投票

看来你的持久卷(PV)确实比5Gi的指定容量大很多。如果底层 hostPath 目录(在您的情况下为 /mnt/raid/db)的可用空间多于 PV 容量中定义的空间,则可能会发生这种情况。

当您在 Kubernetes 中使用本地存储存储类和 hostPath 卷类型定义持久卷时,Kubernetes 不会对底层目录强制执行容量限制。它只是将主机上的指定目录挂载到容器中。

对于挂载目录大小超过PV容量的原因,有以下几种可能的解释:

Disk Size Mismatch: The size of the underlying disk or filesystem (/mnt/raid/db) on the host machine is larger than the 5GB capacity specified in the Persistent Volume.

Data Growth: The data stored within the PostgreSQL database has grown over time and exceeded the initially allocated PV capacity. PostgreSQL databases can grow significantly over time as more data is inserted, updated, and retained.

Misconfiguration: There might have been a misconfiguration in the PV or PVC definitions, causing the PV to be larger than intended. Double-check the YAML definitions for the PV and PVC to ensure that the capacity is indeed set to 5Gi.

Manual Changes: It's also possible that someone manually increased the size of the underlying directory (/mnt/raid/db) on the host machine, leading to a discrepancy between the actual disk size and the PV capacity.

要解决该问题并防止出现进一步的磁盘空间问题:

You can resize the PV to match the actual disk size if needed. This may require recreating the PV and PVC with the correct capacity.
Consider implementing proper monitoring and resource management to prevent future disk space issues. This could include setting up alerts for disk usage thresholds and regularly monitoring database growth.

请记住仔细规划和管理磁盘空间,以确保 Kubernetes 集群和应用程序的最佳性能和可靠性。

© www.soinside.com 2019 - 2024. All rights reserved.