# Set Resource Limits for Namespaces

In 
Published 2022-12-03

This tutorial explains how we can set resource limits for a specific namespace in Kubernetes.

Let's create a namespace using the declarative approach, using the "my-first-namespace.yaml" file we have below :

my-first-namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: my-namespace-1
  labels:
    environment: dev
    project: data-moving

We need to run the following command in order to have the namespaces created:

kubectl apply -f my-first-namespace.yaml

If we want to add resource limits for "my-namespace-1" namespace we need to define a ResourceQuota as below:

my-first-resource-quota.yaml
apiVersion: v1
kind: ResourceQuota
metadata:
 name: quota-for-my-namespace-1
 namespace: my-namespace-1
spec:
 hard:
   requests.cpu: "1"
   requests.memory: 1G
   limits.cpu: "2"
   limits.memory: 2G

and run the following command:

kubectl apply -f my-first-resource-quota.yaml

Now we can see the new resources allocation on the my-namespace-1 namespace:

kubectl describe ns my-namespace-1
Name:         my-namespace-1
Labels:       kubernetes.io/metadata.name=my-namespace-1
Annotations:  <none>
Status:       Active

Resource Quotas
  Name:            quota-for-my-namespace-1
  Resource         Used  Hard
  --------         ---   ---
  limits.cpu       0     2
  limits.memory    0     2G
  requests.cpu     0     1
  requests.memory  0     1G

No LimitRange resource.