142 lines
3.4 KiB
Markdown
142 lines
3.4 KiB
Markdown
|
---
|
||
|
title: Configure a Pod Quota for a Namespace
|
||
|
content_template: templates/task
|
||
|
weight: 60
|
||
|
---
|
||
|
|
||
|
|
||
|
{{% capture overview %}}
|
||
|
|
||
|
This page shows how to set a quota for the total number of Pods that can run
|
||
|
in a namespace. You specify quotas in a
|
||
|
[ResourceQuota](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#resourcequota-v1-core)
|
||
|
object.
|
||
|
|
||
|
{{% /capture %}}
|
||
|
|
||
|
|
||
|
{{% capture prerequisites %}}
|
||
|
|
||
|
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||
|
|
||
|
{{% /capture %}}
|
||
|
|
||
|
|
||
|
{{% capture steps %}}
|
||
|
|
||
|
## 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-pod-example
|
||
|
```
|
||
|
|
||
|
## Create a ResourceQuota
|
||
|
|
||
|
Here is the configuration file for a ResourceQuota object:
|
||
|
|
||
|
{{< code file="quota-pod.yaml" >}}
|
||
|
|
||
|
Create the ResourceQuota:
|
||
|
|
||
|
```shell
|
||
|
kubectl create -f https://k8s.io/docs/tasks/administer-cluster/quota-pod.yaml --namespace=quota-pod-example
|
||
|
```
|
||
|
|
||
|
View detailed information about the ResourceQuota:
|
||
|
|
||
|
```shell
|
||
|
kubectl get resourcequota pod-demo --namespace=quota-pod-example --output=yaml
|
||
|
```
|
||
|
|
||
|
The output shows that the namespace has a quota of two Pods, and that currently there are
|
||
|
no Pods; that is, none of the quota is used.
|
||
|
|
||
|
```yaml
|
||
|
spec:
|
||
|
hard:
|
||
|
pods: "2"
|
||
|
status:
|
||
|
hard:
|
||
|
pods: "2"
|
||
|
used:
|
||
|
pods: "0"
|
||
|
```
|
||
|
|
||
|
Here is the configuration file for a Deployment:
|
||
|
|
||
|
{{< code file="quota-pod-deployment.yaml" >}}
|
||
|
|
||
|
In the configuration file, `replicas: 3` tells Kubernetes to attempt to create three Pods, all running the same application.
|
||
|
|
||
|
Create the Deployment:
|
||
|
|
||
|
```shell
|
||
|
kubectl create -f https://k8s.io/docs/tasks/administer-cluster/quota-pod-deployment.yaml --namespace=quota-pod-example
|
||
|
```
|
||
|
|
||
|
View detailed information about the Deployment:
|
||
|
|
||
|
```shell
|
||
|
kubectl get deployment pod-quota-demo --namespace=quota-pod-example --output=yaml
|
||
|
```
|
||
|
|
||
|
The output shows that even though the Deployment specifies three replicas, only two
|
||
|
Pods were created because of the quota.
|
||
|
|
||
|
```yaml
|
||
|
spec:
|
||
|
...
|
||
|
replicas: 3
|
||
|
...
|
||
|
status:
|
||
|
availableReplicas: 2
|
||
|
...
|
||
|
lastUpdateTime: 2017-07-07T20:57:05Z
|
||
|
message: 'unable to create pods: pods "pod-quota-demo-1650323038-" is forbidden:
|
||
|
exceeded quota: pod-demo, requested: pods=1, used: pods=2, limited: pods=2'
|
||
|
```
|
||
|
|
||
|
## Clean up
|
||
|
|
||
|
Delete your namespace:
|
||
|
|
||
|
```shell
|
||
|
kubectl delete namespace quota-pod-example
|
||
|
```
|
||
|
|
||
|
{{% /capture %}}
|
||
|
|
||
|
{{% capture whatsnext %}}
|
||
|
|
||
|
### For cluster administrators
|
||
|
|
||
|
* [Configure Default Memory Requests and Limits for a Namespace](/docs/tasks/administer-cluster/memory-default-namespace/)
|
||
|
|
||
|
* [Configure Default CPU Requests and Limits for a Namespace](/docs/tasks/administer-cluster/cpu-default-namespace/)
|
||
|
|
||
|
* [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 Quotas for API Objects](/docs/tasks/administer-cluster/quota-api-object/)
|
||
|
|
||
|
### For app developers
|
||
|
|
||
|
* [Assign Memory Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-memory-resource/)
|
||
|
|
||
|
* [Assign CPU Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-cpu-resource/)
|
||
|
|
||
|
* [Configure Quality of Service for Pods](/docs/tasks/configure-pod-container/quality-service-pod/)
|
||
|
|
||
|
{{% /capture %}}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|