Skip to content

Commit 82ced92

Browse files
authored
Merge pull request #40913 from windsonsea/podstart
[zh] sync blog: updates-on-speeding-up-pod-startup.md
2 parents 08e6ea2 + 60f4066 commit 82ced92

File tree

1 file changed

+243
-0
lines changed

1 file changed

+243
-0
lines changed
Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
---
2+
layout: blog
3+
title: "Kubernetes 1.27:关于加快 Pod 启动的进展"
4+
date: 2023-05-15T00:00:00+0000
5+
slug: speed-up-pod-startup
6+
---
7+
<!--
8+
layout: blog
9+
title: "Kubernetes 1.27: updates on speeding up Pod startup"
10+
date: 2023-05-15T00:00:00+0000
11+
slug: speed-up-pod-startup
12+
-->
13+
14+
<!--
15+
**Authors**: Paco Xu (DaoCloud), Sergey Kanzhelev (Google), Ruiwen Zhao (Google)
16+
-->
17+
**作者**:Paco Xu (DaoCloud), Sergey Kanzhelev (Google), Ruiwen Zhao (Google)
18+
**译者**:Michael Yao (DaoCloud)
19+
20+
<!--
21+
How can Pod start-up be accelerated on nodes in large clusters? This is a common issue that
22+
cluster administrators may face.
23+
24+
This blog post focuses on methods to speed up pod start-up from the kubelet side. It does not
25+
involve the creation time of pods by controller-manager through kube-apiserver, nor does it
26+
include scheduling time for pods or webhooks executed on it.
27+
-->
28+
如何在大型集群中加快节点上的 Pod 启动?这是集群管理员可能面临的常见问题。
29+
30+
本篇博文重点介绍了从 kubelet 一侧加快 Pod 启动的方法。它不涉及通过
31+
kube-apiserver 由 controller-manager 创建 Pod 所用的时间,
32+
也不包括 Pod 的调度时间或在其上执行 Webhook 的时间。
33+
34+
<!--
35+
We have mentioned some important factors here to consider from the kubelet's perspective, but
36+
this is not an exhaustive list. As Kubernetes v1.27 is released, this blog highlights
37+
significant changes in v1.27 that aid in speeding up pod start-up.
38+
-->
39+
我们从 kubelet 的角度考虑,在本文提到了一些重要的影响因素,但这并不是详尽罗列。
40+
随着 Kubernetes v1.27 的发布,本文强调了在 v1.27 中有助于加快 Pod 启动的重大变更。
41+
42+
<!--
43+
## Parallel container image pulls
44+
45+
Pulling images always takes some time and what's worse is that image pulls are done serially by
46+
default. In other words, kubelet will send only one image pull request to the image service at
47+
a time. Other image pull requests have to wait until the one being processed is complete.
48+
-->
49+
## 并行容器镜像拉取
50+
51+
拉取镜像总是需要一些时间的,更糟糕的是,镜像拉取默认是串行作业。
52+
换句话说,kubelet 一次只会向镜像服务发送一个镜像拉取请求。
53+
其他的镜像拉取请求必须等到正在处理的拉取请求完成。
54+
55+
<!--
56+
To enable parallel image pulls, set the `serializeImagePulls` field to false in the kubelet
57+
configuration. When `serializeImagePulls` is disabled, requests for image pulls are immediately
58+
sent to the image service and multiple images can be pulled concurrently.
59+
-->
60+
要启用并行镜像拉取,请在 kubelet 配置中将 `serializeImagePulls` 字段设置为 false。
61+
`serializeImagePulls` 被禁用时,将立即向镜像服务发送镜像拉取请求,并可以并行拉取多个镜像。
62+
63+
<!--
64+
### Maximum parallel image pulls will help secure your node from overloading on image pulling
65+
66+
We introduced a new feature in kubelet that sets a limit on the number of parallel image
67+
pulls at the node level. This limit restricts the maximum number of images that can be pulled
68+
simultaneously. If there is an image pull request beyond this limit, it will be blocked until
69+
one of the ongoing image pulls finishes. Before enabling this feature, please ensure that your
70+
container runtime's image service can handle parallel image pulls effectively.
71+
-->
72+
### 设定并行镜像拉取最大值有助于防止节点因镜像拉取而过载
73+
74+
我们在 kubelet 中引入了一个新特性,可以在节点级别设置并行镜像拉取的限值。
75+
此限值限制了可以同时拉取的最大镜像数量。如果有个镜像拉取请求超过了这个限值,
76+
该请求将被阻止,直到其中一个正在进行的镜像拉取完成为止。
77+
在启用此特性之前,请确保容器运行时的镜像服务可以有效处理并行镜像拉取。
78+
79+
<!--
80+
To limit the number of simultaneous image pulls, you can configure the `maxParallelImagePulls`
81+
field in kubelet. By setting `maxParallelImagePulls` to a value of _n_, only _n_ images will
82+
be pulled concurrently. Any additional image pulls beyond this limit will wait until at least
83+
one ongoing pull is complete.
84+
85+
You can find more details in the associated KEP: [Kubelet limit of Parallel Image Pulls](https://kep.k8s.io/3673)
86+
(KEP-3673).
87+
-->
88+
要限制并行镜像拉取的数量,你可以在 kubelet 中配置 `maxParallelImagePulls` 字段。
89+
`maxParallelImagePulls` 的值设置为 **n** 后,并行拉取的镜像数将不能超过 **n** 个。
90+
超过此限值的任何其他镜像拉取请求都需要等到至少一个正在进行的拉取被完成为止。
91+
92+
你可以在关联的 KEP 中找到更多细节:
93+
[Kubelet 并行镜像拉取数限值](https://kep.k8s.io/3673) (KEP-3673)。
94+
95+
<!--
96+
## Raised default API query-per-second limits for kubelet
97+
98+
To improve pod startup in scenarios with multiple pods on a node, particularly sudden scaling
99+
situations, it is necessary for Kubelet to synchronize the pod status and prepare configmaps,
100+
secrets, or volumes. This requires a large bandwidth to access kube-apiserver.
101+
-->
102+
## 提高了 kubelet 默认 API 每秒查询限值
103+
104+
为了在节点上具有多个 Pod 的场景中加快 Pod 启动,特别是在突然扩缩的情况下,
105+
kubelet 需要同步 Pod 状态并准备 ConfigMap、Secret 或卷。这就需要大带宽访问 kube-apiserver。
106+
107+
<!--
108+
In versions prior to v1.27, the default `kubeAPIQPS` was 5 and `kubeAPIBurst` was 10. However,
109+
the kubelet in v1.27 has increased these defaults to 50 and 100 respectively for better performance during
110+
pod startup. It's worth noting that this isn't the only reason why we've bumped up the API QPS
111+
limits for Kubelet.
112+
-->
113+
在 v1.27 之前的版本中,`kubeAPIQPS` 的默认值为 5,`kubeAPIBurst` 的默认值为 10。
114+
然而在 v1.27 中,kubelet 为了提高 Pod 启动性能,将这些默认值分别提高到了 50 和 100。
115+
值得注意的是,这并不是我们提高 kubelet 的 API QPS 限值的唯一原因。
116+
117+
<!--
118+
1. It has a potential to be hugely throttled now (default QPS = 5)
119+
2. In large clusters they can generate significant load anyway as there are a lot of them
120+
3. They have a dedicated PriorityLevel and FlowSchema that we can easily control
121+
-->
122+
1. 现在的情况是 API 请求可能会被过度限制(默认 QPS = 5)
123+
2. 在大型集群中,API 请求仍然可能产生相当大的负载,因为数量很多
124+
3. 我们现在可以轻松控制一个专门为此设计的 PriorityLevel 和 FlowSchema
125+
126+
<!--
127+
Previously, we often encountered `volume mount timeout` on kubelet in node with more than 50 pods
128+
during pod start up. We suggest that cluster operators bump `kubeAPIQPS` to 20 and `kubeAPIBurst` to 40,
129+
especially if using bare metal nodes.
130+
131+
More detials can be found in the KEP <https://kep.k8s.io/1040> and the pull request [#116121](https://github.com/kubernetes/kubernetes/pull/116121).
132+
-->
133+
以前在具有 50 个以上 Pod 的节点中,我们经常在 Pod 启动期间在 kubelet 上遇到 `volume mount timeout`
134+
特别是在使用裸金属节点时,我们建议集群操作员将 `kubeAPIQPS` 提高到 20,`kubeAPIBurst` 提高到 40。
135+
136+
更多细节请参阅 KEP <https://kep.k8s.io/1040>
137+
[PR#116121](https://github.com/kubernetes/kubernetes/pull/116121)
138+
139+
<!--
140+
## Event triggered updates to container status
141+
142+
`Evented PLEG` (PLEG is short for "Pod Lifecycle Event Generator") is set to be in beta for v1.27,
143+
Kubernetes offers two ways for the kubelet to detect Pod lifecycle events, such as a the last
144+
process in a container shutting down.
145+
In Kubernetes v1.27, the _event based_ mechanism has graduated to beta but remains
146+
disabled by default. If you do explicitly switch to event-based lifecycle change detection,
147+
the kubelet is able to start Pods more quickly than with the default approach that relies on polling.
148+
The default mechanism, polling for lifecycle changes, adds a noticeable overhead; this affects
149+
the kubelet's ability to handle different tasks in parallel, and leads to poor performance and
150+
reliability issues. For these reasons, we recommend that you switch your nodes to use
151+
event-based pod lifecycle change detection.
152+
-->
153+
## 事件驱动的容器状态更新
154+
155+
在 v1.27 中,`Evented PLEG`
156+
(PLEG 是英文 Pod Lifecycle Event Generator 的缩写,表示 “Pod 生命周期事件生成器”)
157+
进阶至 Beta 阶段。Kubernetes 为 kubelet 提供了两种方法来检测 Pod 的生命周期事件,
158+
例如容器中最后一个进程关闭。在 Kubernetes v1.27 中,**基于事件的** 机制已进阶至 Beta,
159+
但默认被禁用。如果你显式切换为基于事件的生命周期变更检测,则 kubelet
160+
能够比依赖轮询的默认方法更快地启动 Pod。默认的轮询生命周期变化机制会增加明显的开销,
161+
这会影响 kubelet 处理不同任务的并行能力,并导致性能和可靠性问题。
162+
出于这些原因,我们建议你将节点切换为使用基于事件的 Pod 生命周期变更检测。
163+
164+
<!--
165+
Further details can be found in the KEP <https://kep.k8s.io/3386> and
166+
[Switching From Polling to CRI Event-based Updates to Container Status](/docs/tasks/administer-cluster/switch-to-evented-pleg/).
167+
-->
168+
更多细节请参阅 KEP <https://kep.k8s.io/3386>
169+
[容器状态从轮询切换为基于 CRI 事件更新](/zh-cn/docs/tasks/administer-cluster/switch-to-evented-pleg/)
170+
171+
<!--
172+
## Raise your pod resource limit if needed
173+
174+
During start-up, some pods may consume a considerable amount of CPU or memory. If the CPU limit is
175+
low, this can significantly slow down the pod start-up process. To improve the memory management,
176+
Kubernetes v1.22 introduced a feature gate called MemoryQoS to kubelet. This feature enables
177+
kubelet to set memory QoS at container, pod, and QoS levels for better protection and guaranteed
178+
quality of memory when running with cgroups v2. Although it has benefits, it is possible that
179+
enabling this feature gate may affect the start-up speed of the pod if the pod startup consumes
180+
a large amount of memory.
181+
-->
182+
## 必要时提高 Pod 资源限值
183+
184+
某些 Pod 在启动过程中可能会耗用大量的 CPU 或内存。
185+
如果 CPU 限值较低,则可能会显著降低 Pod 启动过程的速度。
186+
为了改善内存管理,Kubernetes v1.22 引入了一个名为 MemoryQoS 的特性门控。
187+
该特性使 kubelet 能够在容器、Pod 和 QoS 级别上设置内存 QoS,以便更好地保护和确保在运行
188+
CGroup V2 时的内存质量。尽管此特性门控有一定的好处,但如果 Pod 启动消耗大量内存,
189+
启用此特性门控可能会影响 Pod 的启动速度。
190+
191+
<!--
192+
Kubelet configuration now includes `memoryThrottlingFactor`. This factor is multiplied by
193+
the memory limit or node allocatable memory to set the cgroupv2 memory.high value for enforcing
194+
MemoryQoS. Decreasing this factor sets a lower high limit for container cgroups, increasing reclaim
195+
pressure. Increasing this factor will put less reclaim pressure. The default value is 0.8 initially
196+
and will change to 0.9 in Kubernetes v1.27. This parameter adjustment can reduce the potential
197+
impact of this feature on pod startup speed.
198+
199+
Further details can be found in the KEP <https://kep.k8s.io/2570>.
200+
-->
201+
Kubelet 配置现在包括 `memoryThrottlingFactor`。该因子乘以内存限制或节点可分配内存,
202+
可以设置 cgroupv2 memory.high 值来执行 MemoryQoS。
203+
减小该因子将为容器 cgroup 设置较低的上限,同时增加了回收压力。
204+
提高此因子将减少回收压力。默认值最初为 0.8,并将在 Kubernetes v1.27 中更改为 0.9。
205+
调整此参数可以减少此特性对 Pod 启动速度的潜在影响。
206+
207+
更多细节请参阅 KEP <https://kep.k8s.io/2570>
208+
209+
<!--
210+
## What's more?
211+
212+
In Kubernetes v1.26, a new histogram metric `pod_start_sli_duration_seconds` was added for Pod
213+
startup latency SLI/SLO details. Additionally, the kubelet log will now display more information
214+
about pod start-related timestamps, as shown below:
215+
-->
216+
## 更多说明
217+
218+
在 Kubernetes v1.26 中,新增了一个名为 `pod_start_sli_duration_seconds` 的直方图指标,
219+
用于显示 Pod 启动延迟 SLI/SLO 详情。此外,kubelet 日志现在会展示更多与 Pod 启动相关的时间戳信息,如下所示:
220+
221+
> Dec 30 15:33:13.375379 e2e-022435249c-674b9-minion-group-gdj4 kubelet[8362]: I1230 15:33:13.375359 8362 pod_startup_latency_tracker.go:102] "Observed pod startup duration" pod="kube-system/konnectivity-agent-gnc9k" podStartSLOduration=-9.223372029479458e+09 pod.CreationTimestamp="2022-12-30 15:33:06 +0000 UTC" firstStartedPulling="2022-12-30 15:33:09.258791695 +0000 UTC m=+13.029631711" lastFinishedPulling="0001-01-01 00:00:00 +0000 UTC" observedRunningTime="2022-12-30 15:33:13.375009262 +0000 UTC m=+17.145849275" watchObservedRunningTime="2022-12-30 15:33:13.375317944 +0000 UTC m=+17.146157970"
222+
223+
<!--
224+
The SELinux Relabeling with Mount Options feature moved to Beta in v1.27. This feature speeds up
225+
container startup by mounting volumes with the correct SELinux label instead of changing each file
226+
on the volumes recursively. Further details can be found in the KEP <https://kep.k8s.io/1710>.
227+
228+
To identify the cause of slow pod startup, analyzing metrics and logs can be helpful. Other
229+
factorsthat may impact pod startup include container runtime, disk speed, CPU and memory
230+
resources on the node.
231+
-->
232+
SELinux 挂载选项重标记功能在 v1.27 中升至 Beta 版本。
233+
该特性通过挂载具有正确 SELinux 标签的卷来加快容器启动速度,
234+
而不是递归地更改卷上的每个文件。更多细节请参阅 KEP <https://kep.k8s.io/1710>
235+
236+
为了确定 Pod 启动缓慢的原因,分析指标和日志可能会有所帮助。
237+
其他可能会影响 Pod 启动的因素包括容器运行时、磁盘速度、节点上的 CPU 和内存资源。
238+
239+
<!--
240+
SIG Node is responsible for ensuring fast Pod startup times, while addressing issues in large
241+
clusters falls under the purview of SIG Scalability as well.
242+
-->
243+
SIG Node 负责确保 Pod 快速启动,而解决大型集群中的问题则属于 SIG Scalability 的范畴。

0 commit comments

Comments
 (0)