天天看点

ali CNCF pod resources及驱逐策略学习

pod resources

三种主要类型:cpu、memory及ephemeral-storage(GPU 仅仅支持在 limits 部分被指定,单位必须是整数)

ephemeral-storage

1 spec.containers[].resources.limits.ephemeral-storage

2 spec.containers[].resources.requests.ephemeral-storage

3 纯整数或小数形式:E,P,T,G,M,K

4 1024的幂次方:Ei,Pi,Ti,Gi,Mi,Ki

5 Each node has a maximum amount of local ephemeral storage it can provide for Pods.

cpu

1 spec.containers[].resources.limits.cpu

2 docker run 命令中的 --cpu-quota 标志的值

2.1 被乘以 100000 然后 除以 1000

2.2 DOCKER 1C=10万 100000

3 k8s 1000M=1C

4 spec.containers[].resources.requests.cpu

5 docker run 命令中的 --cpu-shares 标志的值

6 Kubernetes 中的一个 cpu 等于

6.1 1 AWS vCPU

6.2 1 GCP Core

6.3 1 Azure vCore

6.4 1 Hyperthread 在带有超线程的裸机 Intel 处理器上

7 允许浮点数请求0.1©等价于表达式 100m,可以看作 “100 millicpu”

memory

0 spec.containers[].resources.limits.memory

1 docker run 命令中的 --memory

2 spec.containers[].resources.requests.memory

3 平均整数或定点整数表示内存:E,P,T,G,M,K

4 或者1024的幂次方Ei,Pi,Ti ,Gi,Mi,Ki

5 找不到符合资源要求的event:failedScheduling

6 资源不足被kill:reason:OOM killed 被终止,OOM 表示 Out Of Memory

7 kubectl get pod -o go-template=’{{range.status.containerStatuses}}{{"Container Name: “}}{{.name}}{{”\r\nLastState: "}}{{.lastState}}{{end}}’ $podname

Pod 创建时归属 QoS 类

创建时候按pod resources 定义信息自动分类,不可手工设置

1 Guaranteed

1.1 Pod 中的每个容器必须指定内存请求和内存限制,并且两者要相等。

1.2 Pod 中的每个容器必须指定 CPU 请求和 CPU 限制,并且两者要相等

2 Burstable

2.1 Pod 不符合 Guaranteed QoS 类的标准。

2.2 Pod 中至少一个容器具有内存或 CPU 请求。

2.3 扩展资源有设置也归属Burstable

3 BestEffort

3.1 Pod 中的容器必须没有设置内存和 CPU 限制或请求

kubectl get pods $PODNAME -o yaml|grep qosClass

k8s 资源资源不足驱逐策略

1 依次驱逐 bestEffort、Burstable、guaranteed

2 按信号触发驱逐决定

2.1 memory.available memory.available := node.status.capacity[memory] - node.stats.memory.workingSet

2.2 nodefs.available nodefs.available := node.stats.fs.available

2.3 nodefs.inodesFree nodefs.inodesFree := node.stats.fs.inodesFree

2.4 imagefs.available imagefs.available := node.stats.runtime.imagefs.available

2.5 imagefs.inodesFree imagefs.inodesFree := node.stats.runtime.imagefs.inodesFree

3 nodefs 文件系统,kubelet 将其用于卷和守护程序日志等。

4 imagefs 文件系统,容器运行时用于保存镜像和容器可写层。

5 默认硬驱逐阈值

5.1 memory.available<100Mi

5.2 nodefs.available<10%

5.3 nodefs.inodesFree<5%

5.4 imagefs.available<15%

6 BestEffort 或 Burstable,其对短缺资源的使用超过了其请求,此类 pod 按优先级排序,然后使用高于请求。

7 Guaranteed pods and Burstable pods whose usage is beneath requests are evicted last

8 Guaranteed Pods are guaranteed only when requests and limits are specified for all the containers and they are equal.