A resource quota, defined by a ResourceQuota object, provides constraints that limit aggregate resource consumption per namespace. It can limit the quantity of objects that can be created in a namespace by type, as well as the total amount of compute resources that may be consumed by resources in that project.
Create a resource quota config file as
apiVersion: v1
kind: ResourceQuota
metadata:
name: pod-demo
spec:
hard:
pods: "2"
In our resource quota file we have limited our number of pod creation to 2.
Create the resource quota as,
Once created , add the resource quota to a namespace as,
When we get the pods, we see we already have 2 pods running in this namespace,
Create a resource quota config file as
apiVersion: v1
kind: ResourceQuota
metadata:
name: pod-demo
spec:
hard:
pods: "2"
In our resource quota file we have limited our number of pod creation to 2.
Create the resource quota as,
[root@manja17-I13330 kubenetes-config]# kubectl create -f basic-resourcequota.yml --namespace=sample-testing
resourcequota "pod-demo" created
Once created , add the resource quota to a namespace as,
[root@manja17-I13330 kubenetes-config]# kubectl get resourcequota --namespace=sample-testing
NAME AGE
pod-demo 55s
When we get the pods, we see we already have 2 pods running in this namespace,
[root@manja17-I13330 kubenetes-config]# kubectl get pods --namespace=sample-testing
NAME READY STATUS RESTARTS AGE
test-service-deploy-85c8787b6f-sfprn 1/1 Running 0 57s
test-service-deploy-85c8787b6f-wvnfc 1/1 Running 0 14s
Now lets try to create a new pod and see how it goes
[root@manja17-I13330 kubenetes-config]# cat basic-single-container-pod.yml
apiVersion: v1
kind: Pod
metadata:
name: testing-service
spec:
containers:
- name: test-ser
image: docker.io/jagadesh1982/testing-service
ports:
- containerPort: 9876
resources:
limits:
memory: "64Mi"
cpu: "500m"
[root@manja17-I13330 kubenetes-config]# kubectl create -f basic-single-container-pod.yml --namespace=sample-testing
Error from server (Forbidden): error when creating "basic-single-container-pod.yml": pods "testing-service" is forbidden: exceeded quota: pod-demo, requested: pods=1, used: pods=2, limited: pods=2
Now when i run the pod creation it gives me an error saying that the resource quota limit for pod is reached and cannot create any more.
No comments :
Post a Comment