Kubernetes Pod 的服务质量(QoS)

网友投稿 1325 2022-11-30

Kubernetes Pod 的服务质量(QoS)

Kubernetes Pod 的服务质量(QoS)

1. 前言

本页介绍怎样配置 Pod 让其获得特定的服务质量(QoS)类。Kubernetes 使用 QoS 类来决定 Pod 的调度和驱逐策略。

2. QoS 类

Kubernetes 创建 Pod 时就给它指定了下列一种 QoS 类:

GuaranteedBurstableBestEffort

创建命名空间

kubectl create namespace qos-example

3. 创建一个 QoS 类为 Guaranteed 的 Pod

对于 QoS 类为 Guaranteed 的 Pod:

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

下面是包含一个容器的 Pod 配置文件。 容器设置了内存请求和内存限制,值都是 200 MiB。 容器设置了 CPU 请求和 CPU 限制,值都是 700 milliCPU:

apiVersion: v1kind: Podmetadata: name: qos-demo namespace: qos-examplespec: containers: - name: qos-demo-ctr image: nginx resources: limits: memory: "200Mi" cpu: "700m" requests: memory: "200Mi" cpu: "700m"

kubectl create -f --namespace=qos-example

查看 Pod 详情:

kubectl get pod qos-demo --namespace=qos-example --output=yaml

结果表明 Kubernetes 为 Pod 配置的 QoS 类为 Guaranteed。 结果也确认了 Pod 容器设置了与内存限制匹配的内存请求,设置了与 CPU 限制匹配的 CPU 请求。

spec: containers: ... resources: limits: cpu: 700m memory: 200Mi requests: cpu: 700m memory: 200Mi ...status: qosClass: Guaranteed

说明: 如果容器指定了自己的内存限制,但没有指定内存请求,Kubernetes 会自动为它指定与内存限制匹配的内存请求。同样,如果容器指定了自己的 CPU 限制,但没有指定 CPU 请求,Kubernetes 会自动为它指定与 CPU 限制匹配的 CPU请求。

4. 创建一个 QoS 类为 Burstable 的 Pod

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

Pod 不符合 Guaranteed QoS 类的标准。Pod 中至少一个容器具有内存或 CPU 请求。

下面是包含一个容器的 Pod 配置文件。 容器设置了内存限制 200 MiB 和内存请求 100 MiB。

apiVersion: v1kind: Podmetadata: name: qos-demo-2 namespace: qos-examplespec: containers: - name: qos-demo-2-ctr image: nginx resources: limits: memory: "200Mi" requests: memory: "100Mi"

kubectl create -f --namespace=qos-example

查看 Pod 详情:

kubectl get pod qos-demo-2 --namespace=qos-example --output=yaml

结果表明 Kubernetes 为 Pod 配置的 QoS 类为 Burstable。

spec: containers: - image: nginx imagePullPolicy: Always name: qos-demo-2-ctr resources: limits: memory: 200Mi requests: memory: 100Mi ...status: qosClass: Burstable

5. 创建一个 QoS 类为 BestEffort 的 Pod

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

下面是包含一个容器的 Pod 配置文件。 容器没有设置内存和 CPU 限制或请求。

apiVersion: v1kind: Podmetadata: name: qos-demo-3 namespace: qos-examplespec: containers: - name: qos-demo-3-ctr image: nginx

kubectl create -f --namespace=qos-example

查看 Pod 详情:

kubectl get pod qos-demo-3 --namespace=qos-example --output=yaml

结果表明 Kubernetes 为 Pod 配置的 QoS 类为 BestEffort。

spec: containers: ... resources: {} ...status: qosClass: BestEffort

6. 创建包含两个容器的 Pod

下面是包含两个容器的 Pod 配置文件。 一个容器指定了内存请求 200 MiB。 另外一个容器没有指定任何请求和限制。

apiVersion: v1kind: Podmetadata: name: qos-demo-4 namespace: qos-examplespec: containers: - name: qos-demo-4-ctr-1 image: nginx resources: requests: memory: "200Mi" - name: qos-demo-4-ctr-2 image: redis

kubectl create -f --namespace=qos-example

查看 Pod 详情:

kubectl get pod qos-demo-4 --namespace=qos-example --output=yaml

结果表明 Kubernetes 为 Pod 配置的 QoS 类为 Burstable:

spec: containers: ... name: qos-demo-4-ctr-1 resources: requests: memory: 200Mi ... name: qos-demo-4-ctr-2 resources: {} ...status: qosClass: Burstable

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Jenkins 基础 03 配置slave
下一篇:Ceph 手把手教你部署ceph集群
相关文章

 发表评论

暂时没有评论,来抢沙发吧~