配置清单说明: 这一块涉及到的概念和配置都相对简单,主要就是在pod配置清单中对所需的资源,也就是CPU/Memory进行要求,也可以限制其自身的CPM/Memory消耗,以免拖垮所在Node节点甚至整个集群 [root@master chapter4]# kubectl explain pod.spec.containers.resourcesKIND: PodVERSION: v1RESOURCE: resources DESCRIPTION: Compute Resources required by this container. Cannot be updated. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/ ResourceRequirements describes the compute resource requirements.FIELDS: limits #限制资源可用的最大值,即硬限制 Limits describes the maximum amount of compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/ requests #属性定义其请求的确保可用值,即容器运行可能用不到这些额度的资源,使用到时必须确保有如此多的资源可用 Requests describes the minimum amount of compute resources required. If Requests is omitted fora container, it defaults to Limits ifthat is explicitly specified, otherwise to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/ 配置举例: [root@master chapter4]# cat stress-pod.yaml apiVersion: v1kind: Podmetadata: name: stress-podspec: containers: - name: stress image: ikubernetes/stress-ng command: [“/usr/bin/stress-ng”, “-c 1”, “-m 1”, “—metrics-brief”] resources: requests: memory: “128Mi” cpu: “200m” limits: memory: “512Mi” cpu: “400m” 上面的配置清单中,其请求使用的cpu资源大小为200m,这意味着一个CPU核心足以确保其期望的最快方式运行 另外,配置清单中期望使用的内存大小为128Mi,不过其运行时未必真的会用到这么多,考虑到内存为非压缩型资源,其超出指定的大小在运行时存在被OOMKilled杀死的可能性,于是请求值也应该就是其理想中使用的内存空间上限 PS:关于资源需求和限制这一块的内容不止这些,本次实验的目的只需要理解和会用即可,还涉及到其他一些内容和使用方式可以参考文档 相关文档:https://www.cnblogs.com/luoahong/p/13452597.html