As mentioned above, resource quotas under the specified name space, limiting the number of resource objects and certain types of resources, you can ResourceQuota
specify the quota
Create a namespace
We create a new namespace to demonstrate
kubectl create namespace quota-object-example
Create a resource quota
The following are the objects of quota allocation of resources
admin/resource/quota-objects.yaml
apiVersion: v1
kind: ResourceQuota
metadata:
name: object-quota-demo
spec:
hard:
persistentvolumeclaims: "1"
services.loadbalancers: "2"
services.nodeports: "0"
By kubectl apply
Create Quota objects
kubectl apply -f https://k8s.io/examples/admin/resource/quota-objects.yaml --namespace=quota-object-example
View detailed information resource quota
kubectl get resourcequota object-quota-demo --namespace=quota-object-example --output=yaml
status:
hard:
persistentvolumeclaims: "1"
services.loadbalancers: "2"
services.nodeports: "0"
used:
persistentvolumeclaims: "0"
services.loadbalancers: "0"
services.nodeports: "0"
Output information is displayed in quota-object-example
the name space, only allow at most one PersistentVolumeClaim
, up to two LoadBalancer
types of services, and does not allow NodePort
the type of service
CreatePersistentVolumeClaim
The following is to create a PersistentVolumeClaim
file object
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: pvc-quota-demo
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
It is created by the command
kubectl apply -f https://k8s.io/examples/admin/resource/quota-objects-pvc.yaml --namespace=quota-object-example
Confirmation has been created:
kubectl get `persistentvolumeclaims` --namespace=quota-object-example
NAME STATUS
pvc-quota-demo Pending
Information display output persistentvolumeclaims
object has been created and the statepending
The following attempts to re-create aPersistentVolumeClaim
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: pvc-quota-demo-2
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 4Gi
Create a command execution
kubectl apply -f https://k8s.io/examples/admin/resource/quota-objects-pvc-2.yaml --namespace=quota-object-example
persistentvolumeclaims "pvc-quota-demo-2" is forbidden:
exceeded quota: object-quota-demo, requested: persistentvolumeclaims=1,
used: persistentvolumeclaims=1, limited: persistentvolumeclaims=1
Can be seen by output, the second persistantPersistentVolumeClaim
was not created because resource quota exceeded
NOTE: The following may be used to string types can be used resource quota
String | API objects |
---|---|
"pods" | Under |
"services | Service |
"replicationcontrollers" | ReplicationController |
"resourcequotas" | ResourceQuota |
"secrets" | Secret |
"configmaps" | configMap |
"persistentvolumeclaims" | PersistentVolumeClaim |
"services.nodeports" | Service of type NodePort |
"services.loadbalancers" | Service of type LoadBalancer |
Delete resource quota
kubectl delete namespace quota-object-example