注:如下只是在yaml文件中進行資源限制的一個片斷,並非完整的yaml文件api
// cgroup-pod.yaml spec: containers: - name: xxx image: xxx ports: - protocol: TCP containerPort: 80 resources: limits: //硬限制 cpu: "4" memory: 2Gi requests: //運行pod時請求的資源數量 cpu: 260m memory: 260Mi
//計算資源配額ide
// compute-resource.yaml apiVersion: v1 kind: ResourceQuota metadata: name: compute-resources spec: hard: pods: "20" //全部pod數量不能夠超過20個 requests.cpu: "20" //初始請求的CPU不能夠超過20m requests.memory: 100Gi //初始請求的內存不能夠超過100G limits.cpu: "40" //CPU的硬限制 limits.memory: 200Gi //內存的硬限制
//資源對象數量配額限制code
// object-counts.yaml apiVersion: v1 kind: ResourceQuota metadata: name: object-counts spec: hard: configmaps: "10" //最多能夠建立10個configmap persistentvolumeclaims: "4" //最多能夠建立4個PVC replicationcontrollers: "20" //最多能夠建立20個RC資源對象 secrets: "10" //最多能夠建立10個secrets service.loadbalancers: "2" //最多能夠建立2個svc
//配置CPU和內存的limitRange對象
// limitRange.yaml apiVersion: v1 kind: LimitRange metadata: name: mem-limit-range spec: limits: - default: memory: 50Gi //硬限制 cpu: 5 //硬限制 defaultRequest: //初始請求 memory: 1Gi cpu: 1 type: Container //限制對象爲容器