2017-03-14 21:41:51 +00:00
|
|
|
---
|
2017-06-08 22:13:29 +00:00
|
|
|
title: Limit Storage Consumption
|
2017-03-14 21:41:51 +00:00
|
|
|
---
|
2017-04-26 03:50:33 +00:00
|
|
|
|
2017-04-09 22:12:45 +00:00
|
|
|
{% capture overview %}
|
2017-03-14 21:41:51 +00:00
|
|
|
|
|
|
|
This example demonstrates an easy way to limit the amount of storage consumed in a namespace.
|
|
|
|
|
2017-07-28 15:23:11 +00:00
|
|
|
The following resources are used in the demonstration: [ResourceQuota](/docs/concepts/policy/resource-quotas/),
|
|
|
|
[LimitRange](/docs/tasks/configure-pod-container/limit-range/),
|
2017-04-09 22:12:45 +00:00
|
|
|
and [PersistentVolumeClaim](/docs/concepts/storage/persistent-volumes/).
|
2017-03-14 21:41:51 +00:00
|
|
|
|
2017-04-09 22:12:45 +00:00
|
|
|
{% endcapture %}
|
2017-03-14 21:41:51 +00:00
|
|
|
|
2017-04-09 22:12:45 +00:00
|
|
|
{% capture prerequisites %}
|
2017-03-14 21:41:51 +00:00
|
|
|
|
2017-04-09 22:12:45 +00:00
|
|
|
* {% include task-tutorial-prereqs.md %}
|
|
|
|
|
|
|
|
{% endcapture %}
|
|
|
|
|
|
|
|
{% capture steps %}
|
|
|
|
## Scenario: Limiting Storage Consumption
|
2017-03-14 21:41:51 +00:00
|
|
|
|
|
|
|
The cluster-admin is operating a cluster on behalf of a user population and the admin wants to control
|
|
|
|
how much storage a single namespace can consume in order to control cost.
|
|
|
|
|
|
|
|
The admin would like to limit:
|
|
|
|
|
|
|
|
1. The number of persistent volume claims in a namespace
|
|
|
|
2. The amount of storage each claim can request
|
|
|
|
3. The amount of cumulative storage the namespace can have
|
|
|
|
|
|
|
|
|
|
|
|
## LimitRange to limit requests for storage
|
|
|
|
|
|
|
|
Adding a `LimitRange` to a namespace enforces storage request sizes to a minimum and maximum. Storage is requested
|
|
|
|
via `PersistentVolumeClaim`. The admission controller that enforces limit ranges will reject any PVC that is above or below
|
|
|
|
the values set by the admin.
|
|
|
|
|
|
|
|
In this example, a PVC requesting 10Gi of storage would be rejected because it exceeds the 2Gi max.
|
|
|
|
|
|
|
|
```
|
|
|
|
apiVersion: v1
|
|
|
|
kind: LimitRange
|
|
|
|
metadata:
|
|
|
|
name: storagelimits
|
|
|
|
spec:
|
|
|
|
limits:
|
|
|
|
- type: PersistentVolumeClaim
|
|
|
|
max:
|
|
|
|
storage: 2Gi
|
|
|
|
min:
|
|
|
|
storage: 1Gi
|
|
|
|
```
|
|
|
|
|
2017-07-28 15:23:11 +00:00
|
|
|
Minimum storage requests are used when the underlying storage provider requires certain minimums. For example,
|
|
|
|
AWS EBS volumes have a 1Gi minimum requirement.
|
2017-03-14 21:41:51 +00:00
|
|
|
|
|
|
|
## StorageQuota to limit PVC count and cumulative storage capacity
|
|
|
|
|
|
|
|
Admins can limit the number of PVCs in a namespace as well as the cumulative capacity of those PVCs. New PVCs that exceed
|
|
|
|
either maximum value will be rejected.
|
|
|
|
|
2017-07-28 15:23:11 +00:00
|
|
|
In this example, a 6th PVC in the namespace would be rejected because it exceeds the maximum count of 5. Alternatively,
|
2017-03-14 21:41:51 +00:00
|
|
|
a 5Gi maximum quota when combined with the 2Gi max limit above, cannot have 3 PVCs where each has 2Gi. That would be 6Gi requested
|
2017-07-28 15:23:11 +00:00
|
|
|
for a namespace capped at 5Gi.
|
2017-03-14 21:41:51 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
apiVersion: v1
|
|
|
|
kind: ResourceQuota
|
|
|
|
metadata:
|
|
|
|
name: storagequota
|
|
|
|
spec:
|
|
|
|
hard:
|
|
|
|
persistentvolumeclaims: "5"
|
|
|
|
requests.storage: "5Gi"
|
|
|
|
```
|
|
|
|
|
2017-04-09 22:12:45 +00:00
|
|
|
{% endcapture %}
|
|
|
|
|
|
|
|
{% capture discussion %}
|
|
|
|
|
2017-07-28 15:23:11 +00:00
|
|
|
## Summary
|
2017-03-14 21:41:51 +00:00
|
|
|
|
|
|
|
A limit range can put a ceiling on how much storage is requested while a resource quota can effectively cap the storage
|
2017-07-28 15:23:11 +00:00
|
|
|
consumed by a namespace through claim counts and cumulative storage capacity. The allows a cluster-admin to plan their
|
2017-03-14 21:41:51 +00:00
|
|
|
cluster's storage budget without risk of any one project going over their allotment.
|
2017-04-09 22:12:45 +00:00
|
|
|
|
|
|
|
{% endcapture %}
|
|
|
|
|
2017-04-26 03:50:33 +00:00
|
|
|
{% include templates/task.md %}
|