K8s resource limit
Note: The following is only a fragment of resource restriction in yaml file, not a complete yaml file, just an essay of my own.
1. Resource limits for pods: [root@master limit]# vim cgroup-pod.yaml spec: containers: - name: xxx image: xxx ports: - protocol: TCP containerPort: 80 resources: limits: #Hard limits cpu: "4" memory: 2Gi requests: #Number of resources requested when running pod cpu: 260m memory: 260Mi2. Namespace-based resource limits (a namespace can be specified) 1) Calculate resource quotas [root@master limit]# vim compute-resource.yaml apiVersion: v1kind: ResourceQuotamedata: name: compute-resourcesspec: hard: pods: "20" #No more than 20 pods requests.cpu: "20" #Initial request CPU cannot exceed 20m requests.memory: 100Gi #Initial request memory cannot exceed 100 gigabytes limits.cpu: "40" #CPU Hard Limits limits.memory: 200Gi #Hard limit for memory 2) Quota limit for number of resource objects [root@master limit]# vim object-counts.yaml apiVersion: v1kind: ResourceQuotametwork: name: object-countsspec: hard: configmaps: "10" #You can create up to 10 configmaps persistentvolumeclaims: "4" You can create up to 4 PVCs replicationcontrollers: "20" #Up to 20 RC resource objects can be created secrets: "10" #You can create up to 10 secrets service.loadbalancers: "2" #Up to 2 svcs can be created 3) Configure CPU and memory limitRange[root@master limit]# vim limitRange.yaml apiVersion: v1kind: LimitRangemetatus: name: mem-limit-rangespec: limits: - default: memory: 50Gi #Hard limits cpu: 5 #Hard limits defaultRequest: #Initial Request memory: 1Gi cpu: 1 type: Container #Limit objects to containers
--------This article ends here, thanks for reading-------