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.