K8S学习笔记(十)- K8S Pod详解 - 服务质量Qos

K8S学习笔记(十)- K8S Pod详解 - 服务质量Qos

三月 24, 2022

概述

Kubernetes 使用 QoS 类来决定 Pod 的调度和驱逐策略。
kubernetes 创建Pod的时候就会指定QoS。
QoS分为如下的三类:

  • ① Guaranteed
  • ② Burstable
  • ③ BestEffort

Qos之Guaranteed

概述

对于 QoS 类为 Guaranteed 的 Pod:

  • Pod 中的每个容器,包含初始化容器,必须指定内存请求和内存限制,并且两者要相等。
  • Pod 中的每个容器,包含初始化容器,必须指定 CPU 请求和 CPU 限制,并且两者要相等。

示例

创建qos-demo.yaml文件,内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
apiVersion: v1
kind: Pod
metadata:
name: qos-demo
namespace: qos-example
spec:
containers:
- name: qos-demo-ctr
image: nginx
resources:
limits:
memory: "200Mi"
cpu: "700m"
requests:
memory: "200Mi"
cpu: "700m"
1
2
3
4
5
6
7
kubectl create -f qos-demo.yaml 

# 查看
kubectl get pod qos-demo -n qos-example -o yaml

# 删除
kubectl delete -f qos-demo.yaml

Qos之Burstable

概述

如果满足下面条件,将会指定 Pod 的 QoS 类为 Burstable:

  • Pod 不符合 Guaranteed QoS 类的标准。
  • Pod 中至少一个容器具有内存或 CPU 请求,但是值不相等。

示例

创建qos-demo-2.yaml文件,内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
apiVersion: v1
kind: Pod
metadata:
name: qos-demo-2
namespace: qos-example
spec:
containers:
- name: qos-demo-2-ctr
image: nginx
resources:
limits:
memory: "200Mi"
requests:
memory: "100Mi"
1
2
3
4
5
6
7
kubectl create -f qos-demo-2.yaml 

# 查看
kubectl get pod qos-demo-2 -n qos-example -o yaml

# 删除
kubectl delete -f qos-demo2.yaml

Qos之BestEffort

概述

对于 QoS 类为 BestEffort 的 Pod,Pod 中的容器必须没有设置内存和 CPU 限制或请求。

示例

创建qos-demo-3.yaml文件,内容如下:

1
2
3
4
5
6
7
8
9
apiVersion: v1
kind: Pod
metadata:
name: qos-demo-3
namespace: qos-example
spec:
containers:
- name: qos-demo-3-ctr
image: nginx
1
2
3
4
5
6
7
kubectl create -f qos-demo-3.yaml 

# 查看Pod
kubectl get pod qos-demo-3 -n qos-example -o yaml

# 删除
kubectl delete -f qos-demo3.yaml

Qos的应用

一旦出现OOM,kubernetes为了保证服务的可用,会先删除QoS为BestEffort的Pod,然后删除QoS为Burstable的Pod,最后删除QoS为Guaranteed 的Pod。