EtcdDatabaseHighFragmentationRatio
EtcdDatabaseHighFragmentationRatio
Description
This alert fires when the etcd database has a high ratio of fragmented space relative to its total allocated size.
Fragmentation builds up over time as keys are deleted or overwritten — etcd retains the allocated disk space but leaves gaps that are no longer in use. A high fragmentation ratio means etcd is holding significantly more disk space than the actual data requires, which wastes storage and can push the database toward its quota limit unnecessarily.
Possible Causes:
- High churn of Kubernetes objects (frequent creates/deletes of Pods, Jobs, Events, etc.)
- Large volumes of etcd revisions accumulating without compaction
- Compaction running but defragmentation not being performed afterwards
- Expired leases or deleted secrets/configmaps leaving fragmented space
- A recent large deletion (e.g. namespace cleanup, batch job teardown)
Severity estimation
Low to Medium severity — etcd continues to function normally, but left unattended this leads to quota exhaustion.
- Low if fragmentation is high but total database size is well within quota
- Medium if fragmentation is contributing to the database approaching its quota (
EtcdDatabaseQuotaLowSpacemay fire soon) - High if quota is nearly full — etcd will reject all writes once the quota is exceeded
Defragmentation is a routine maintenance operation and should be performed without urgency unless quota pressure is also present.
Troubleshooting steps
-
Check current etcd database size and fragmentation
- Command / Action:
- Query etcd metrics to see in-use vs allocated size
-
kubectl exec -n kube-system <etcd-pod> – etcdctl endpoint status –write-out=table
- Expected result:
- Output shows
DB SIZE(allocated) andDB SIZE IN USEcolumns; the gap between them is fragmented space
- Output shows
- additional info:
- Set
ETCDCTL_API=3and pass--cacert,--cert,--keyflags if required by your cluster
- Set
- Command / Action:
-
Verify compaction is running
- Command / Action:
- Check the etcd pod logs for compaction activity
-
kubectl logs -n kube-system <etcd-pod> | grep -i compact
- Expected result:
- Regular compaction log entries are visible
- additional info:
- Kubernetes runs auto-compaction via
kube-apiserver --etcd-compaction-interval(default 5 min); if missing, compaction may be disabled
- Kubernetes runs auto-compaction via
- Command / Action:
-
Check the Prometheus metric directly
- Command / Action:
- Evaluate the fragmentation ratio in Prometheus
-
(1 - etcd_mvcc_db_total_size_in_use_in_bytes / etcd_mvcc_db_total_size_in_bytes) * 100
- Expected result:
- Value below ~50%; alert typically fires above that threshold
- additional info:
- Run per member (
by (endpoint)) to identify if fragmentation is isolated to one etcd member
- Run per member (
- Command / Action:
-
Run defragmentation on each etcd member
- Command / Action:
- Defragment one member at a time to avoid quorum loss
-
kubectl exec -n kube-system <etcd-pod> – etcdctl defrag –endpoints=https://127.0.0.1:2379
-
kubectl exec -n kube-system <etcd-pod> – etcdctl defrag –endpoints=<member-2-url>,<member-3-url>
- Expected result:
- Each member reports
Finished defragmenting etcd member[...]; DB SIZE drops after each run
- Each member reports
- additional info:
- Defragmentation briefly locks the member — always defragment one member at a time and confirm it returns healthy before proceeding to the next
- Command / Action:
-
Verify etcd cluster health after defragmentation
- Command / Action:
- Confirm all members are healthy and the leader is stable
-
kubectl exec -n kube-system <etcd-pod> – etcdctl endpoint health –write-out=table
-
kubectl exec -n kube-system <etcd-pod> – etcdctl endpoint status –write-out=table
- Expected result:
- All endpoints report
healthy: true; DB SIZE IN USE is now close to DB SIZE
- All endpoints report
- additional info:
- If a member remains unhealthy after defrag, check its logs and cross-reference with
EtcdMembersDownorEtcdNoLeader
- If a member remains unhealthy after defrag, check its logs and cross-reference with
- Command / Action:
-
Confirm the alert resolves
- Command / Action:
- Re-check the fragmentation ratio metric after defragmentation completes
-
(1 - etcd_mvcc_db_total_size_in_use_in_bytes / etcd_mvcc_db_total_size_in_bytes) * 100
- Expected result:
- Ratio drops below the alert threshold
- additional info:
- If fragmentation returns quickly, investigate object churn — high Pod/Event/Job turnover may require tuning
--etcd-compaction-intervalor--auto-compaction-retention
- If fragmentation returns quickly, investigate object churn — high Pod/Event/Job turnover may require tuning
- Command / Action:
Additional resources
- etcd maintenance — defragmentation
- etcd endpoint status reference
- Kubernetes etcd compaction settings
- Related alert: EtcdDatabaseQuotaLowSpace
- Related alert: EtcdExcessiveDatabaseGrowth
- Related alert: EtcdNoLeader