We have 3 namespaces on a kubernetes cluster
dev-test / build / prod
I want to limit the resource usage for dev-test
& build
only. Can I set the resource quotas only for these namespaces without specifying (default-) resource requests & limits on the pod/container level?
If the resource usage on the limited namespaces is low, prod can use the rest completely, and it can grow only to a limited value, so prod resource usage is protected.
apiVersion: v1
kind: ResourceQuota
metadata:
name: dev-test
spec:
hard:
cpu: "2"
memory: 8Gi
Is this enough?
Yes you can use kubeclt CLI as well to define resource quota per namespace.
Example :
$ kubectl create namespace testquotaspace
namespace/testquotaspace created
$ kubectl create quota testquota -n testquotaspace --hard=cpu=1,memory=8Gi
resourcequota/testquota created
$ kubectl describe namespaces testquotaspace
Name: testquotaspace
Labels: <none>
Annotations: <none>
Status: Active
Resource Quotas
Name: testquota
Resource Used Hard
-------- --- ---
cpu 0 1
memory 0 8Gi
No LimitRange resource.
you can choose to limit the other objects you need as well like PODS/SERVICE/PVC etc .. Just run help on CLI and will have all details
$ kubectl create quota --help
Create a resourcequota with the specified name, hard limits and optional scopes
Aliases:
quota, resourcequota
Examples:
# Create a new resourcequota named my-quota
kubectl create quota my-quota
--hard=cpu=1,memory=1G,pods=2,services=3,replicationcontrollers=2,resourcequotas=1,secrets=5,persistentvolumeclaims=10
If you do need yamls you can generate as follow and pipe to a file as needed
$ kubectl create quota testquota -n testquotaspace --hard=cpu=1,memory=8Gi --dry-run -o yaml
apiVersion: v1
kind: ResourceQuota
metadata:
creationTimestamp: null
name: testquota
namespace: testquotaspace
spec:
hard:
cpu: "1"
memory: 8Gi
Yes, you can set resource limits per namespace using ResourceQuota object:
apiVersion: v1
kind: ResourceQuota
metadata:
name: mem-cpu-demo
spec:
hard:
requests.cpu: "1"
requests.memory: 1Gi
limits.cpu: "2"
limits.memory: 2Gi
From kubernetes documentation.