6.5.3.2. 使用卷插件消耗容器资源
在创建 pod 时,您可以使用 Downward API 注入有关使用卷插件的计算资源请求和限制的信息。
流程
使用卷插件:
在创建 pod 配置时,使用
spec.volumes.downwardAPI.items
字段来描述与spec.resources
字段对应的所需资源:.... spec: containers: - name: client-container image: gcr.io/google_containers/busybox:1.24 command: ["sh", "-c", "while true; do echo; if [[ -e /etc/cpu_limit ]]; then cat /etc/cpu_limit; fi; if [[ -e /etc/cpu_request ]]; then cat /etc/cpu_request; fi; if [[ -e /etc/mem_limit ]]; then cat /etc/mem_limit; fi; if [[ -e /etc/mem_request ]]; then cat /etc/mem_request; fi; sleep 5; done"] resources: requests: memory: "32Mi" cpu: "125m" limits: memory: "64Mi" cpu: "250m" volumeMounts: - name: podinfo mountPath: /etc readOnly: false volumes: - name: podinfo downwardAPI: items: - path: "cpu_limit" resourceFieldRef: containerName: client-container resource: limits.cpu - path: "cpu_request" resourceFieldRef: containerName: client-container resource: requests.cpu - path: "mem_limit" resourceFieldRef: containerName: client-container resource: limits.memory - path: "mem_request" resourceFieldRef: containerName: client-container resource: requests.memory ....
如果容器配置中没有包含资源限制,Downward API 会默认使用节点的 CPU 和内存可分配量。
从
volume-pod.yaml
文件创建 pod:$ oc create -f volume-pod.yaml