Examples of scheduling resource quota kubernetes

Series catalog

As mentioned above, resource quotas under the specified name space, limiting the number of resource objects and certain types of resources, you can ResourceQuotaspecify 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 applyCreate 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-examplethe name space, only allow at most one PersistentVolumeClaim, up to two LoadBalancertypes of services, and does not allow NodePortthe type of service

CreatePersistentVolumeClaim

The following is to create a PersistentVolumeClaimfile 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 persistentvolumeclaimsobject 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 persistantPersistentVolumeClaimwas 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

Guess you like

Origin www.cnblogs.com/tylerzhou/p/11031693.html