Skip to content

Commit f26e212

Browse files
committed
Resource Quota Per VolumeAttributesClass
1 parent cd79f1d commit f26e212

File tree

3 files changed

+306
-0
lines changed

3 files changed

+306
-0
lines changed

content/en/docs/concepts/policy/resource-quotas.md

+252
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ Resources specified on the quota outside of the allowed set results in a validat
228228
| `NotBestEffort` | Match pods that do not have best effort quality of service. |
229229
| `PriorityClass` | Match pods that references the specified [priority class](/docs/concepts/scheduling-eviction/pod-priority-preemption). |
230230
| `CrossNamespacePodAffinity` | Match pods that have cross-namespace pod [(anti)affinity terms](/docs/concepts/scheduling-eviction/assign-pod-node). |
231+
| `VolumeAttributesClass` | Match persistentvolumeclaims that references the specified [volume attributes class](/docs/concepts/storage/volume-attributes-classes). |
231232

232233
The `BestEffort` scope restricts a quota to tracking the following resource:
233234

@@ -459,6 +460,257 @@ With the above configuration, pods can use `namespaces` and `namespaceSelector`
459460
if the namespace where they are created have a resource quota object with
460461
`CrossNamespacePodAffinity` scope and a hard limit greater than or equal to the number of pods using those fields.
461462

463+
### Resource Quota Per VolumeAttributesClass
464+
465+
{{< feature-state feature_gate_name="VolumeAttributesClass" >}}
466+
467+
PersistentVolumeClaims can be created with a specific [volume attributes class](/docs/concepts/storage/volume-attributes-classes/), and might be modified after creation. You can control a PVC's consumption of storage resources based on the associated volume attributes classes, by using the `scopeSelector` field in the quota spec.
468+
469+
The PVC references the associated volume attributes class by the following fields:
470+
471+
* `spec.volumeAttributesClassName`
472+
* `status.currentVolumeAttributesClassName`
473+
* `status.modifyVolumeStatus.targetVolumeAttributesClassName`
474+
475+
A quota is matched and consumed only if `scopeSelector` in the quota spec selects the PVC.
476+
477+
When the quota is scoped for the volume attributes class using the `scopeSelector` field, the quota object is restricted to track only the following resources:
478+
479+
* `persistentvolumeclaims`
480+
* `requests.storage`
481+
482+
This example creates a quota object and matches it with PVC at specific volume attributes classes. The example works as follows:
483+
484+
- PVCs in the cluster have at least one of the three volume attributes classes, "gold", "silver", "copper".
485+
- One quota object is created for each volume attributes class.
486+
487+
Save the following YAML to a file `quota-vac.yaml`.
488+
489+
{{% code_sample file="policy/quota-vac.yaml" %}}
490+
491+
Apply the YAML using `kubectl create`.
492+
493+
```shell
494+
kubectl create -f ./quota-vac.yaml
495+
```
496+
497+
```
498+
resourcequota/pvcs-gold created
499+
resourcequota/pvcs-silver created
500+
resourcequota/pvcs-copper created
501+
```
502+
503+
Verify that `Used` quota is `0` using `kubectl describe quota`.
504+
505+
```shell
506+
kubectl describe quota
507+
```
508+
509+
```
510+
Name: pvcs-gold
511+
Namespace: default
512+
Resource Used Hard
513+
-------- ---- ----
514+
persistentvolumeclaims 0 10
515+
requests.storage 0 10Gi
516+
517+
518+
Name: pvcs-silver
519+
Namespace: default
520+
Resource Used Hard
521+
-------- ---- ----
522+
persistentvolumeclaims 0 10
523+
requests.storage 0 20Gi
524+
525+
526+
Name: pvcs-copper
527+
Namespace: default
528+
Resource Used Hard
529+
-------- ---- ----
530+
persistentvolumeclaims 0 10
531+
requests.storage 0 30Gi
532+
```
533+
534+
Create a pvc with volume attributes class "gold". Save the following YAML to a file `gold-vac-pvc.yaml`.
535+
536+
{{% code_sample file="policy/gold-vac-pvc.yaml" %}}
537+
538+
Apply it with `kubectl create`.
539+
540+
```shell
541+
kubectl create -f ./gold-vac-pvc.yaml
542+
```
543+
544+
Verify that "Used" stats for "gold" volume attributes class quota, `pvcs-gold` has changed and that the other two quotas are unchanged.
545+
546+
```shell
547+
kubectl describe quota
548+
```
549+
550+
```
551+
Name: pvcs-gold
552+
Namespace: default
553+
Resource Used Hard
554+
-------- ---- ----
555+
persistentvolumeclaims 1 10
556+
requests.storage 2Gi 10Gi
557+
558+
559+
Name: pvcs-silver
560+
Namespace: default
561+
Resource Used Hard
562+
-------- ---- ----
563+
persistentvolumeclaims 0 10
564+
requests.storage 0 20Gi
565+
566+
567+
Name: pvcs-copper
568+
Namespace: default
569+
Resource Used Hard
570+
-------- ---- ----
571+
persistentvolumeclaims 0 10
572+
requests.storage 0 30Gi
573+
```
574+
575+
Once the PVC is bound, it is allowed to modify the desired volume attributes class. Let's change it to "silver" with kubectl patch.
576+
577+
```shell
578+
kubectl patch pvc gold-vac-pvc --type='merge' -p '{"spec":{"volumeAttributesClassName":"silver"}}'
579+
```
580+
581+
Verify that "Used" stats for "silver" volume attributes class quota, `pvcs-silver` has changed, `pvcs-copper` is unchanged, and `pvcs-gold` might be unchanged or released, which depends on the PVC's status.
582+
583+
```shell
584+
kubectl describe quota
585+
```
586+
587+
```
588+
Name: pvcs-gold
589+
Namespace: default
590+
Resource Used Hard
591+
-------- ---- ----
592+
persistentvolumeclaims 1 10
593+
requests.storage 2Gi 10Gi
594+
595+
596+
Name: pvcs-silver
597+
Namespace: default
598+
Resource Used Hard
599+
-------- ---- ----
600+
persistentvolumeclaims 1 10
601+
requests.storage 2Gi 20Gi
602+
603+
604+
Name: pvcs-copper
605+
Namespace: default
606+
Resource Used Hard
607+
-------- ---- ----
608+
persistentvolumeclaims 0 10
609+
requests.storage 0 30Gi
610+
```
611+
612+
Let's change it to "copper" with kubectl patch.
613+
614+
```shell
615+
kubectl patch pvc gold-vac-pvc --type='merge' -p '{"spec":{"volumeAttributesClassName":"copper"}}'
616+
```
617+
618+
Verify that "Used" stats for "copper" volume attributes class quota, `pvcs-copper` has changed, `pvcs-silver` and `pvcs-gold` might be unchanged or released, which depends on the PVC's status.
619+
620+
```shell
621+
kubectl describe quota
622+
```
623+
624+
```
625+
Name: pvcs-gold
626+
Namespace: default
627+
Resource Used Hard
628+
-------- ---- ----
629+
persistentvolumeclaims 1 10
630+
requests.storage 2Gi 10Gi
631+
632+
633+
Name: pvcs-silver
634+
Namespace: default
635+
Resource Used Hard
636+
-------- ---- ----
637+
persistentvolumeclaims 1 10
638+
requests.storage 2Gi 20Gi
639+
640+
641+
Name: pvcs-copper
642+
Namespace: default
643+
Resource Used Hard
644+
-------- ---- ----
645+
persistentvolumeclaims 1 10
646+
requests.storage 2Gi 30Gi
647+
```
648+
649+
Print the manifest of the PVC using the following command:
650+
651+
```shell
652+
kubectl get pvc gold-vac-pvc -o yaml
653+
```
654+
655+
It might show the following output:
656+
657+
```yaml
658+
apiVersion: v1
659+
kind: PersistentVolumeClaim
660+
metadata:
661+
name: gold-vac-pvc
662+
spec:
663+
accessModes:
664+
- ReadWriteOnce
665+
resources:
666+
requests:
667+
storage: 2Gi
668+
storageClassName: default
669+
volumeAttributesClassName: copper
670+
status:
671+
accessModes:
672+
- ReadWriteOnce
673+
capacity:
674+
storage: 2Gi
675+
currentVolumeAttributesClassName: gold
676+
phase: Bound
677+
modifyVolumeStatus:
678+
status: InProgress
679+
targetVolumeAttributesClassName: silver
680+
storageClassName: default
681+
```
682+
683+
Wait a moment for the volume modification to complete, then verify the quota again.
684+
685+
```shell
686+
kubectl describe quota
687+
```
688+
689+
```
690+
Name: pvcs-gold
691+
Namespace: default
692+
Resource Used Hard
693+
-------- ---- ----
694+
persistentvolumeclaims 0 10
695+
requests.storage 0 10Gi
696+
697+
698+
Name: pvcs-silver
699+
Namespace: default
700+
Resource Used Hard
701+
-------- ---- ----
702+
persistentvolumeclaims 0 10
703+
requests.storage 0 20Gi
704+
705+
706+
Name: pvcs-copper
707+
Namespace: default
708+
Resource Used Hard
709+
-------- ---- ----
710+
persistentvolumeclaims 1 10
711+
requests.storage 2Gi 30Gi
712+
```
713+
462714
## Requests compared to Limits {#requests-vs-limits}
463715

464716
When allocating compute resources, each container may specify a request and a limit value for either CPU or memory.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: PersistentVolumeClaim
3+
metadata:
4+
name: gold-vac-pvc
5+
spec:
6+
accessModes:
7+
- ReadWriteOnce
8+
resources:
9+
requests:
10+
storage: 2Gi
11+
storageClassName: # change this to the name of the storage class you want to use
12+
volumeAttributesClassName: gold
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
apiVersion: v1
2+
kind: List
3+
items:
4+
- apiVersion: v1
5+
kind: ResourceQuota
6+
metadata:
7+
name: pvcs-gold
8+
spec:
9+
hard:
10+
requests.storage: "10Gi"
11+
persistentvolumeclaims: "10"
12+
scopeSelector:
13+
matchExpressions:
14+
- operator: In
15+
scopeName: VolumeAttributesClass
16+
values: ["gold"]
17+
- apiVersion: v1
18+
kind: ResourceQuota
19+
metadata:
20+
name: pvcs-silver
21+
spec:
22+
hard:
23+
requests.storage: "20Gi"
24+
persistentvolumeclaims: "10"
25+
scopeSelector:
26+
matchExpressions:
27+
- operator: In
28+
scopeName: VolumeAttributesClass
29+
values: ["silver"]
30+
- apiVersion: v1
31+
kind: ResourceQuota
32+
metadata:
33+
name: pvcs-copper
34+
spec:
35+
hard:
36+
requests.storage: "30Gi"
37+
persistentvolumeclaims: "10"
38+
scopeSelector:
39+
matchExpressions:
40+
- operator: In
41+
scopeName: VolumeAttributesClass
42+
values: ["copper"]

0 commit comments

Comments
 (0)