Configure Quotas for API Objects
Kubernetes Docs · نسخهٔ f284a9e7c87f · CC BY 4.0 برای مستندات و مجوزهای همراه
<!-- overview -->
This page shows how to configure quotas for API objects, including PersistentVolumeClaims and Services. A quota restricts the number of objects, of a particular type, that can be created in a namespace. You specify quotas in a [ResourceQuota](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#resourcequota-v1-core) object.
{{% heading "prerequisites" %}}
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
<!-- steps -->
Create a namespace
Create a namespace so that the resources you create in this exercise are isolated from the rest of your cluster.
kubectl create namespace quota-object-exampleCreate a ResourceQuota
Here is the configuration file for a ResourceQuota object:
{{% code_sample file="admin/resource/quota-objects.yaml" %}}
Create the ResourceQuota:
kubectl apply -f https://k8s.io/examples/admin/resource/quota-objects.yaml --namespace=quota-object-exampleView detailed information about the ResourceQuota:
kubectl get resourcequota object-quota-demo --namespace=quota-object-example --output=yamlThe output shows that in the quota-object-example namespace, there can be at most one PersistentVolumeClaim, at most two Services of type LoadBalancer, and no Services of type NodePort.
status:
hard:
persistentvolumeclaims: "1"
services.loadbalancers: "2"
services.nodeports: "0"
used:
persistentvolumeclaims: "0"
services.loadbalancers: "0"
services.nodeports: "0"Create a PersistentVolumeClaim
Here is the configuration file for a PersistentVolumeClaim object:
{{% code_sample file="admin/resource/quota-objects-pvc.yaml" %}}
Create the PersistentVolumeClaim:
kubectl apply -f https://k8s.io/examples/admin/resource/quota-objects-pvc.yaml --namespace=quota-object-exampleVerify that the PersistentVolumeClaim was created:
kubectl get persistentvolumeclaims --namespace=quota-object-exampleThe output shows that the PersistentVolumeClaim exists and has status Pending:
NAME STATUS
pvc-quota-demo PendingAttempt to create a second PersistentVolumeClaim
Here is the configuration file for a second PersistentVolumeClaim:
{{% code_sample file="admin/resource/quota-objects-pvc-2.yaml" %}}
Attempt to create the second PersistentVolumeClaim:
kubectl apply -f https://k8s.io/examples/admin/resource/quota-objects-pvc-2.yaml --namespace=quota-object-exampleThe output shows that the second PersistentVolumeClaim was not created, because it would have exceeded the quota for the namespace.
persistentvolumeclaims "pvc-quota-demo-2" is forbidden:
exceeded quota: object-quota-demo, requested: persistentvolumeclaims=1,
used: persistentvolumeclaims=1, limited: persistentvolumeclaims=1Notes
These are the strings used to identify API resources that can be constrained by quotas:
<table> <tr><th>String</th><th>API Object</th></tr> <tr><td>"pods"</td><td>Pod</td></tr> <tr><td>"services"</td><td>Service</td></tr> <tr><td>"replicationcontrollers"</td><td>ReplicationController</td></tr> <tr><td>"resourcequotas"</td><td>ResourceQuota</td></tr> <tr><td>"secrets"</td><td>Secret</td></tr> <tr><td>"configmaps"</td><td>ConfigMap</td></tr> <tr><td>"persistentvolumeclaims"</td><td>PersistentVolumeClaim</td></tr> <tr><td>"services.nodeports"</td><td>Service of type NodePort</td></tr> <tr><td>"services.loadbalancers"</td><td>Service of type LoadBalancer</td></tr> </table>
Clean up
Delete your namespace:
kubectl delete namespace quota-object-example{{% heading "whatsnext" %}}
For cluster administrators
- Configure Default Memory Requests and Limits for a Namespace
- Configure Default CPU Requests and Limits for a Namespace
- Configure Minimum and Maximum Memory Constraints for a Namespace
- Configure Minimum and Maximum CPU Constraints for a Namespace
- Configure Memory and CPU Quotas for a Namespace
- Configure a Pod Quota for a Namespace
For app developers
- Assign Memory Resources to Containers and Pods
- Assign CPU Resources to Containers and Pods
- Assign Pod-level CPU and memory resources
- Configure Quality of Service for Pods