⎈ k8s knowledge compiler

Configure a Pod Quota for a Namespace [page]deterministic

Restrict how many Pods you can create within a namespace.

tasks

This page shows how to set a quota for the total number of Pods that can run in a [Namespace](#gloss:namespace). You specify quotas in a [ResourceQuota](/docs/reference/kubernetes-api/policy-resources/resource-quota-v1/) object.

##

You must have access to create namespaces in your cluster.

## 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 an example manifest for a ResourceQuota:

Create the ResourceQuota:

```shell kubectl apply -f https://k8s.io/examples/admin/resource/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 an example manifest for a [deployment](#gloss:deployment):

In that manifest, `replicas: 3` tells Kubernetes to attempt to create three new Pods, all running the same application.

Create the Deployment:

```shell kubectl apply -f https://k8s.io/examples/admin/resource/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 you defined earlier:

```yaml spec: ... replicas: 3 ... status: availableReplicas: 2 ... lastUpdateTime: 2021-04-02T20: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' ```

### Choice of resource

In this task you have defined a ResourceQuota that limited the total number of Pods, but you could also limit the total number of other kinds of object. For example, you might decide to limit how many [CronJobs](#gloss:cronjob) that can live in a single namespace.

## Clean up

Delete your namespace:

```shell kubectl delete namespace quota-pod-example ```

##

### For cluster administrators

* [Configure Default Memory Requests and Limits for a Namespace](/docs/tasks/administer-cluster/manage-resources/memory-default-namespace/)

* [Configure Default CPU Requests and Limits for a Namespace](/docs/tasks/administer-cluster/manage-resources/cpu-default-namespace/)

* [Configure Minimum and Maximum Memory Constraints for a Namespace](/docs/tasks/administer-cluster/manage-resources/memory-constraint-namespace/)

* [Configure Minimum and Maximum CPU Constraints for a Namespace](/docs/tasks/administer-cluster/manage-resources/cpu-constraint-namespace/)

* [Configure Memory and CPU Quotas for a Namespace](/docs/tasks/administer-cluster/manage-resources/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/)

* [Assign Pod-level CPU and memory resources](/docs/tasks/configure-pod-container/assign-pod-level-resources/)

* [Configure Quality of Service for Pods](/docs/tasks/configure-pod-container/quality-service-pod/)

Sources

tasks/administer-cluster/manage-resources/quota-pod-namespace.md · docConfigure a Pod Quota for a Namespace

Related (12)

references NamespaceNamespace conf=1
references Deploymentdeployment conf=1
references CronJobCronJobs conf=1
part_of {{% heading "prerequisites" %}}describes conf=1
part_of Create a namespacedescribes conf=1
part_of Create a ResourceQuotadescribes conf=1
part_of Clean updescribes conf=1
part_of {{% heading "whatsnext" %}}describes conf=1
part_of Choice of resourcedescribes conf=1
part_of For cluster administratorsdescribes conf=1
part_of For app developersdescribes conf=1
api_for Namespacedocuments API object conf=1

← all Docs