一、简述
kubernetes创建资源时,一般需要设置容器的资源(CPU和内存)需求(request,最低保障数量)和资源限制(limits最大限额)。CPU单位一般为阿拉伯数字或m,如500m(millicores)代表0.5个逻辑cpu,内存单位一般为Mi或Gi。
spec.containers[].resources.limits.cpuspec.containers[].resources.limits.memoryspec.containers[].resources.limits.hugepages-<size>spec.containers[].resources.requests.cpuspec.containers[].resources.requests.memoryspec.containers[].resources.requests.hugepages-<size>
对容器资源限制官方使用文档:
[root@master1 yaml]# kubectl explain pods.spec.containers.resources
KIND: Pod
VERSION: v1
RESOURCE: resources <Object>
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 <map[string]string>
Limits describes the maximum amount of compute resources allowed. More
info:
https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/
requests <map[string]string>
Requests describes the minimum amount of compute resources required. If
Requests is omitted for a container, it defaults to Limits if that is
explicitly specified, otherwise to an implementation-defined value. More
info:
https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/
二、实例
分别限制cpu和内存
apiVersion: v1
kind: Pod
metadata:
name: pod-normal
labels:
app: myapp
tier: frontend
spec:
containers:
- name: myapp
image: ikubernetes/myapp:v1
resources:
requests:
memory: "256Mi"
cpu: "500m"
limits:
memory: "512Mi"
cpu: "1"
三、Pod的Qos参数
Qos(Quality of Service,服务质量),由系统自动分类,一般有如下三个资源类别选项:
- Guranteed
- Burstable
- BestEffort
1.Guranteed
当一个pod中的所有容器,同时设置CPU和内存的requests和limits,且CPU的requests等于limits,内存的requests等于limits,即cpu.limits=cpu.requests, memory.limits=memory.requests。资源使用优先级最高,当节点资源紧缺时,会被优先保留。
2.Burstable
一个pod中,至少有一个容器设置了CPU或内存资源的requests属性。资源使用优先级中等。
3.BestEffort
pod资源中没有任何一个requests或limits属性,资源使用优先级最低,当节点资源紧缺时,会被优先关闭。
琼杰笔记






评论前必须登录!
注册