Pod资源限制介绍
1.Pod资源配额有两种:
-
申请配额:
spec.containers[].resources.requests.cpu
spec.containers[].resources.requests.memory -
限制配额:
spec.containers[].resources.limits.cpu
spec.containers[].resources.limits.memory
申请配额是当容器就分配到了这么多资源,限制配额是容器最多能申请这么多资源
memory单位可以写为: M或者Mi,1M=1000kb,1Mi=1024kb
cpu单位可以写为:m或者数字,(1000m=1核CPU),(500m=0.5CPU),(250m=0.25CPU)
Pod资源限制示例
下面根据官方示例,创建一个pod,pod中两个容器,分别为mysql和wordpress,限制参数请结合上面部分
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
apiVersion: v1 kind: Pod metadata: name: frontend spec: containers: - name: db image: mysql env: - name: MYSQL_ROOT_PASSWORD value: "password" resources: requests: memory: "64Mi" cpu: "250m" limits: memory: "128Mi" cpu: "500m" - name: wp image: wordpress resources: requests: memory: "64M" cpu: "0.25" limits: memory: "128M" cpu: "0.5" kubectl apply -f limit_pod.yaml kubectl get pods -o wide | grep frontend frontend 2/2 Running 2 2m45s 10.244.3.45 k8s-node01 <none> <none> |
kubectl describe pods/frontend