2017-08-07 22:30:29 +00:00
|
|
|
---
|
|
|
|
title: Configure Quotas for API Objects
|
2018-05-05 16:00:51 +00:00
|
|
|
content_template: templates/task
|
2017-08-07 22:30:29 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
{{% capture overview %}}
|
2017-08-07 22:30:29 +00:00
|
|
|
|
|
|
|
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
|
2018-05-05 16:00:51 +00:00
|
|
|
[ResourceQuota](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#resourcequota-v1-core)
|
2017-08-07 22:30:29 +00:00
|
|
|
object.
|
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
{{% /capture %}}
|
2017-08-07 22:30:29 +00:00
|
|
|
|
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
{{% capture prerequisites %}}
|
2017-08-07 22:30:29 +00:00
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
2017-08-07 22:30:29 +00:00
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
{{% /capture %}}
|
2017-08-07 22:30:29 +00:00
|
|
|
|
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
{{% capture steps %}}
|
2017-08-07 22:30:29 +00:00
|
|
|
|
|
|
|
## Create a namespace
|
|
|
|
|
|
|
|
Create a namespace so that the resources you create in this exercise are
|
|
|
|
isolated from the rest of your cluster.
|
|
|
|
|
|
|
|
```shell
|
|
|
|
kubectl create namespace quota-object-example
|
|
|
|
```
|
|
|
|
|
|
|
|
## Create a ResourceQuota
|
|
|
|
|
|
|
|
Here is the configuration file for a ResourceQuota object:
|
|
|
|
|
2018-07-03 20:39:21 +00:00
|
|
|
{{< codenew file="admin/resource/quota-objects.yaml" >}}
|
2017-08-07 22:30:29 +00:00
|
|
|
|
|
|
|
Create the ResourceQuota:
|
|
|
|
|
|
|
|
```shell
|
2018-07-03 20:39:21 +00:00
|
|
|
kubectl create -f https://k8s.io/examples/admin/resource/quota-objects.yaml --namespace=quota-object-example
|
2017-08-07 22:30:29 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
View detailed information about the ResourceQuota:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
kubectl get resourcequota object-quota-demo --namespace=quota-object-example --output=yaml
|
|
|
|
```
|
|
|
|
|
|
|
|
The 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
|
2017-09-29 21:20:40 +00:00
|
|
|
of type NodePort.
|
2017-08-07 22:30:29 +00:00
|
|
|
|
|
|
|
```yaml
|
|
|
|
status:
|
|
|
|
hard:
|
|
|
|
persistentvolumeclaims: "1"
|
|
|
|
services.loadbalancers: "2"
|
|
|
|
services.nodeports: "0"
|
|
|
|
used:
|
|
|
|
persistentvolumeclaims: "0"
|
|
|
|
services.loadbalancers: "0"
|
|
|
|
services.nodeports: "0"
|
|
|
|
```
|
|
|
|
|
2017-11-27 03:59:42 +00:00
|
|
|
## Create a PersistentVolumeClaim
|
2017-08-07 22:30:29 +00:00
|
|
|
|
|
|
|
Here is the configuration file for a PersistentVolumeClaim object:
|
|
|
|
|
2018-07-03 20:39:21 +00:00
|
|
|
{{< codenew file="admin/resource/quota-objects-pvc.yaml" >}}
|
2017-08-07 22:30:29 +00:00
|
|
|
|
|
|
|
Create the PersistentVolumeClaim:
|
|
|
|
|
|
|
|
```shell
|
2018-07-03 20:39:21 +00:00
|
|
|
kubectl create -f https://k8s.io/examples/admin/resource/quota-objects-pvc.yaml --namespace=quota-object-example
|
2017-08-07 22:30:29 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Verify that the PersistentVolumeClaim was created:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
kubectl get persistentvolumeclaims --namespace=quota-object-example
|
|
|
|
```
|
|
|
|
|
|
|
|
The output shows that the PersistentVolumeClaim exists and has status Pending:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
NAME STATUS
|
|
|
|
pvc-quota-demo Pending
|
|
|
|
```
|
|
|
|
|
2017-11-27 03:59:42 +00:00
|
|
|
## Attempt to create a second PersistentVolumeClaim
|
2017-08-07 22:30:29 +00:00
|
|
|
|
|
|
|
Here is the configuration file for a second PersistentVolumeClaim:
|
|
|
|
|
2018-07-03 20:39:21 +00:00
|
|
|
{{< codenew file="admin/resource/quota-objects-pvc-2.yaml" >}}
|
2017-08-07 22:30:29 +00:00
|
|
|
|
|
|
|
Attempt to create the second PersistentVolumeClaim:
|
|
|
|
|
|
|
|
```shell
|
2018-07-03 20:39:21 +00:00
|
|
|
kubectl create -f https://k8s.io/examples/admin/resource/quota-objects-pvc-2.yaml --namespace=quota-object-example
|
2017-08-07 22:30:29 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
The 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=1
|
|
|
|
```
|
|
|
|
|
|
|
|
## Notes
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
kubectl delete namespace quota-object-example
|
|
|
|
```
|
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
{{% /capture %}}
|
2017-08-07 22:30:29 +00:00
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
{{% capture whatsnext %}}
|
2017-08-07 22:30:29 +00:00
|
|
|
|
|
|
|
### For cluster administrators
|
|
|
|
|
2017-08-16 02:19:58 +00:00
|
|
|
* [Configure Default Memory Requests and Limits for a Namespace](/docs/tasks/administer-cluster/memory-default-namespace/)
|
2017-08-07 22:30:29 +00:00
|
|
|
|
2017-08-17 23:07:20 +00:00
|
|
|
* [Configure Default CPU Requests and Limits for a Namespace](/docs/tasks/administer-cluster/cpu-default-namespace/)
|
2017-08-07 22:30:29 +00:00
|
|
|
|
|
|
|
* [Configure Minimum and Maximum Memory Constraints for a Namespace](/docs/tasks/administer-cluster/memory-constraint-namespace/)
|
|
|
|
|
|
|
|
* [Configure Minimum and Maximum CPU Constraints for a Namespace](/docs/tasks/administer-cluster/cpu-constraint-namespace/)
|
|
|
|
|
|
|
|
* [Configure Memory and CPU Quotas for a Namespace](/docs/tasks/administer-cluster/quota-memory-cpu-namespace/)
|
|
|
|
|
|
|
|
* [Configure a Pod Quota for a Namespace](/docs/tasks/administer-cluster/quota-pod-namespace/)
|
|
|
|
|
|
|
|
### For app developers
|
|
|
|
|
|
|
|
* [Assign Memory Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-memory-resource/)
|
|
|
|
|
2017-08-15 05:39:25 +00:00
|
|
|
* [Assign CPU Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-cpu-resource/)
|
2017-08-07 22:30:29 +00:00
|
|
|
|
|
|
|
* [Configure Quality of Service for Pods](/docs/tasks/configure-pod-container/quality-service-pod/)
|
|
|
|
|
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
{{% /capture %}}
|
|
|
|
|
2017-08-07 22:30:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|