一个容器对资源的需要有两个方面:
- requests,所需资源的最低保障,这是作为k8s调度器进行调度的衡量条件的指标
- limits,资源限制,所需资源的上限,是硬限制
CPU
一颗物理核心cpu在通过超线程技术会被虚拟成多颗逻辑cpu,在docker中一颗逻辑cpu等于1000millicores
,那500m的cpu就行于0.5颗逻辑cpu。
内存
进率为1000时,单位为: E, P, T, G, M, K
进率为1024时,单位为:Ei, Pi, Ti, Gi, Mi, Ki
当对pod进行资源限制后,在pod的详细信息里会自动配置"Qos class"字段,字段有如下值:
Guranteed: 确保,保证。pod中每个容器同时设置了cpu和内存的requests和limits,
且cpu.limits=cpu.requests,memory.limits=memory=request,该种pod优先级最高
Burstable: 至少。pod中至少一个容器设置cpu或内存资源的requests属性,该种pod的优先级居中
BestEffort: pod中没有任何一个容器设置了requests或limits属性;该种pod的优先级别最低
资源限制配置参数
KIND: Pod
VERSION: v1
FIELDS:
spec <Object>
containers <[]Object>
resources <Object>
limits <map[string]string> 允许的最大资源计算量
memory: <string>
cpu: <string>
requests <map[string]string> 请求的最少资源计算量
memory: <string>
cpu: <string>
资源限制事例
k8s@node01:~/my_manifests/scheduler$ cat resources-limits.yaml
apiVersion: v1
kind: Pod
metadata:
name: myapp
spec:
containers:
- name: myapp-pod
image: ikubernetes/myapp:v1
imagePullPolicy: IfNotPresent
resources:
requests:
cpu: "200m"
memory: "128Mi"
limits:
cpu: "200m"
memory: "128Mi"
k8s@node01:~/my_manifests/scheduler$ kubectl apply -f resources-limits.yaml
pod/myapp created
# 查看Pod详细信息
k8s@node01:~/my_manifests/scheduler$ kubectl describe pods/myapp
...
Limits:
cpu: 200m
memory: 128Mi
Requests:
cpu: 200m
memory: 128Mi
...
QoS Class: Guaranteed
...
# 因requests和limits一样,QoS Class为Guaranteed