Skip to content

Commit 43de768

Browse files
authored
Merge pull request #28020 from CaoDonghui123/fix1
[zh]Resync tasks files[8]
2 parents 96c83e7 + a7e39ec commit 43de768

File tree

4 files changed

+131
-54
lines changed

4 files changed

+131
-54
lines changed

content/zh/docs/tasks/configure-pod-container/assign-cpu-resource.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ kubectl top pod cpu-demo --namespace=cpu-example
166166

167167
<!--
168168
This example output shows that the Pod is using 974 milliCPU, which is
169-
just a bit less than the limit of 1 CPU specified in the Pod configuration.
169+
slightly less than the limit of 1 CPU specified in the Pod configuration.
170170
-->
171-
此示例输出显示 Pod 使用的是 974 milliCPU,即仅略低于 Pod 配置中指定的 1 个 CPU 的限制。
171+
此示例输出显示 Pod 使用的是 974 milliCPU,即略低于 Pod 配置中指定的 1 个 CPU 的限制。
172172

173173
```
174174
NAME CPU(cores) MEMORY(bytes)

content/zh/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes.md

Lines changed: 109 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ weight: 110
88
<!--
99
This page shows how to configure liveness, readiness and startup probes for Containers.
1010
11-
The [kubelet](/docs/admin/kubelet/) uses liveness probes to know when to
12-
restart a Container. For example, liveness probes could catch a deadlock,
11+
The [kubelet](/docs/reference/command-line-tools-reference/kubelet/) uses liveness probes to know when to
12+
restart a container. For example, liveness probes could catch a deadlock,
1313
where an application is running, but unable to make progress. Restarting a
14-
Container in such a state can help to make the application more available
14+
container in such a state can help to make the application more available
1515
despite bugs.
1616
-->
1717
这篇文章介绍如何给容器配置存活、就绪和启动探测器。
@@ -22,12 +22,12 @@ despite bugs.
2222
这样的情况下重启容器有助于让应用程序在有问题的情况下更可用。
2323

2424
<!--
25-
The kubelet uses readiness probes to know when a Container is ready to start
26-
accepting traffic. A Pod is considered ready when all of its Containers are ready.
25+
The kubelet uses readiness probes to know when a container is ready to start
26+
accepting traffic. A Pod is considered ready when all of its containers are ready.
2727
One use of this signal is to control which Pods are used as backends for Services.
2828
When a Pod is not ready, it is removed from Service load balancers.
2929
30-
The kubelet uses startup probes to know when a Container application has started.
30+
The kubelet uses startup probes to know when a container application has started.
3131
If such a probe is configured, it disables liveness and readiness checks until
3232
it succeeds, making sure those probes don't interfere with the application startup.
3333
This can be used to adopt liveness checks on slow starting containers, avoiding them
@@ -45,7 +45,7 @@ kubelet 使用启动探测器可以知道应用程序容器什么时候启动了
4545

4646
## {{% heading "prerequisites" %}}
4747

48-
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
48+
{{< include "task-tutorial-prereqs.md" >}}
4949

5050
<!-- steps -->
5151

@@ -56,7 +56,7 @@ Many applications running for long periods of time eventually transition to
5656
broken states, and cannot recover except by being restarted. Kubernetes provides
5757
liveness probes to detect and remedy such situations.
5858
59-
In this exercise, you create a Pod that runs a Container based on the
59+
In this exercise, you create a Pod that runs a container based on the
6060
`k8s.gcr.io/busybox` image. Here is the configuration file for the Pod:
6161
-->
6262
## 定义存活命令 {#define-a-liveness-command}
@@ -70,16 +70,16 @@ Kubernetes 提供了存活探测器来发现并补救这种情况。
7070
{{< codenew file="pods/probe/exec-liveness.yaml" >}}
7171

7272
<!--
73-
In the configuration file, you can see that the Pod has a single Container.
73+
In the configuration file, you can see that the Pod has a single `Container`.
7474
The `periodSeconds` field specifies that the kubelet should perform a liveness
7575
probe every 5 seconds. The `initialDelaySeconds` field tells the kubelet that it
76-
should wait 5 second before performing the first probe. To perform a probe, the
77-
kubelet executes the command `cat /tmp/healthy` in the Container. If the
78-
command succeeds, it returns 0, and the kubelet considers the Container to be alive and
79-
healthy. If the command returns a non-zero value, the kubelet kills the Container
76+
should wait 5 seconds before performing the first probe. To perform a probe, the
77+
kubelet executes the command `cat /tmp/healthy` in the target container. If the
78+
command succeeds, it returns 0, and the kubelet considers the container to be alive and
79+
healthy. If the command returns a non-zero value, the kubelet kills the container
8080
and restarts it.
8181
82-
When the Container starts, it executes this command:
82+
When the container starts, it executes this command:
8383
-->
8484
在这个配置文件中,可以看到 Pod 中只有一个容器。
8585
`periodSeconds` 字段指定了 kubelet 应该每 5 秒执行一次存活探测。
@@ -95,7 +95,7 @@ kubelet 在容器内执行命令 `cat /tmp/healthy` 来进行探测。
9595
```
9696

9797
<!--
98-
For the first 30 seconds of the Container's life, there is a `/tmp/healthy` file.
98+
For the first 30 seconds of the container's life, there is a `/tmp/healthy` file.
9999
So during the first 30 seconds, the command `cat /tmp/healthy` returns a success
100100
code. After 30 seconds, `cat /tmp/healthy` returns a failure code.
101101
@@ -195,14 +195,14 @@ image.
195195
{{< codenew file="pods/probe/http-liveness.yaml" >}}
196196

197197
<!--
198-
In the configuration file, you can see that the Pod has a single Container.
198+
In the configuration file, you can see that the Pod has a single container.
199199
The `periodSeconds` field specifies that the kubelet should perform a liveness
200200
probe every 3 seconds. The `initialDelaySeconds` field tells the kubelet that it
201201
should wait 3 seconds before performing the first probe. To perform a probe, the
202-
kubelet sends an HTTP GET request to the server that is running in the Container
202+
kubelet sends an HTTP GET request to the server that is running in the container
203203
and listening on port 8080. If the handler for the server's `/healthz` path
204-
returns a success code, the kubelet considers the Container to be alive and
205-
healthy. If the handler returns a failure code, the kubelet kills the Container
204+
returns a success code, the kubelet considers the container to be alive and
205+
healthy. If the handler returns a failure code, the kubelet kills the container
206206
and restarts it.
207207
-->
208208
在这个配置文件中,可以看到 Pod 也只有一个容器。
@@ -217,14 +217,14 @@ Any code greater than or equal to 200 and less than 400 indicates success. Any
217217
other code indicates failure.
218218
219219
You can see the source code for the server in
220-
[server.go](https://github.com/kubernetes/kubernetes/blob/master/test/images/agnhost/liveness/server.go).
220+
[server.go](https://github.com/kubernetes/kubernetes/blob/{{< param "githubbranch" >}}/test/images/agnhost/liveness/server.go).
221221
222-
For the first 10 seconds that the Container is alive, the `/healthz` handler
222+
For the first 10 seconds that the container is alive, the `/healthz` handler
223223
returns a status of 200. After that, the handler returns a status of 500.
224224
-->
225225
任何大于或等于 200 并且小于 400 的返回代码标示成功,其它返回代码都标示失败。
226226

227-
可以在这里看服务的源码 [server.go](https://github.com/kubernetes/kubernetes/blob/master/test/images/agnhost/liveness/server.go)
227+
可以在这里看服务的源码 [server.go](https://github.com/kubernetes/kubernetes/blob/{{< param "githubbranch" >}}/test/images/agnhost/liveness/server.go)。
228228

229229
容器存活的最开始 10 秒中,`/healthz` 处理程序返回一个 200 的状态码。之后处理程序返回 500 的状态码。
230230

@@ -242,9 +242,9 @@ http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
242242
```
243243

244244
<!--
245-
The kubelet starts performing health checks 3 seconds after the Container starts.
245+
The kubelet starts performing health checks 3 seconds after the container starts.
246246
So the first couple of health checks will succeed. But after 10 seconds, the health
247-
checks will fail, and the kubelet will kill and restart the Container.
247+
checks will fail, and the kubelet will kill and restart the container.
248248
249249
To try the HTTP liveness check, create a Pod:
250250
-->
@@ -259,7 +259,7 @@ kubectl apply -f https://k8s.io/examples/pods/probe/http-liveness.yaml
259259

260260
<!--
261261
After 10 seconds, view Pod events to verify that liveness probes have failed and
262-
the Container has been restarted:
262+
the container has been restarted:
263263
-->
264264
10 秒之后,通过看 Pod 事件来检测存活探测器已经失败了并且容器被重新启动了。
265265

@@ -269,7 +269,7 @@ kubectl describe pod liveness-http
269269

270270
<!--
271271
In releases prior to v1.13 (including v1.13), if the environment variable
272-
`http_proxy` (or `HTTP_PROXY`) is set on the node where a pod is running,
272+
`http_proxy` (or `HTTP_PROXY`) is set on the node where a Pod is running,
273273
the HTTP liveness probe uses that proxy.
274274
In releases after v1.13, local HTTP proxy environment variable settings do not
275275
affect the HTTP liveness probe.
@@ -281,7 +281,7 @@ affect the HTTP liveness probe.
281281
<!--
282282
## Define a TCP liveness probe
283283
284-
A third type of liveness probe uses a TCP Socket. With this configuration, the
284+
A third type of liveness probe uses a TCP socket. With this configuration, the
285285
kubelet will attempt to open a socket to your container on the specified port.
286286
If it can establish a connection, the container is considered healthy, if it
287287
can't it is considered a failure.
@@ -298,13 +298,13 @@ can't it is considered a failure.
298298
As you can see, configuration for a TCP check is quite similar to an HTTP check.
299299
This example uses both readiness and liveness probes. The kubelet will send the
300300
first readiness probe 5 seconds after the container starts. This will attempt to
301-
connect to the `goproxy` container on port 8080. If the probe succeeds, the pod
301+
connect to the `goproxy` container on port 8080. If the probe succeeds, the Pod
302302
will be marked as ready. The kubelet will continue to run this check every 10
303303
seconds.
304304
305305
In addition to the readiness probe, this configuration includes a liveness probe.
306306
The kubelet will run the first liveness probe 15 seconds after the container
307-
starts. Just like the readiness probe, this will attempt to connect to the
307+
starts. Similar to the readiness probe, this will attempt to connect to the
308308
`goproxy` container on port 8080. If the liveness probe fails, the container
309309
will be restarted.
310310
@@ -317,7 +317,7 @@ To try the TCP liveness check, create a Pod:
317317

318318
除了就绪探测,这个配置包括了一个存活探测。
319319
kubelet 会在容器启动 15 秒后进行第一次存活探测。
320-
就像就绪探测一样,会尝试连接 `goproxy` 容器的 8080 端口。
320+
与就绪探测类似,会尝试连接 `goproxy` 容器的 8080 端口。
321321
如果存活探测失败,这个容器会被重新启动。
322322

323323
```shell
@@ -439,6 +439,14 @@ Readiness probes runs on the container during its whole lifecycle.
439439
就绪探测器在容器的整个生命周期中保持运行状态。
440440
{{< /note >}}
441441

442+
<!--
443+
Liveness probes *do not* wait for readiness probes to succeed. If you want to wait before executing a liveness probe you should use initialDelaySeconds or a startupProbe.
444+
-->
445+
{{< caution >}}
446+
活跃性探测器 *不等待* 就绪性探测器成功。
447+
如果要在执行活跃性探测器之前等待,应该使用 initialDelaySeconds 或 startupProbe。
448+
{{< /caution >}}
449+
442450
<!--
443451
Readiness probes are configured similarly to liveness probes. The only difference
444452
is that you use the `readinessProbe` field instead of the `livenessProbe` field.
@@ -496,8 +504,8 @@ seconds. Minimum value is 1.
496504
* `timeoutSeconds`: Number of seconds after which the probe times out. Defaults
497505
to 1 second. Minimum value is 1.
498506
* `successThreshold`: Minimum consecutive successes for the probe to be
499-
considered successful after having failed. Defaults to 1. Must be 1 for
500-
liveness and startup Probes. Minimum value is 1.
507+
considered successful after having failed. Defaults to 1. Must be 1 for liveness
508+
and startup Probes. Minimum value is 1.
501509
* `failureThreshold`: When a probe fails, Kubernetes will
502510
try `failureThreshold` times before giving up. Giving up in case of liveness probe means restarting the container. In case of readiness probe the Pod will be marked Unready.
503511
Defaults to 3. Minimum value is 1.
@@ -511,6 +519,7 @@ Defaults to 3. Minimum value is 1.
511519
存活探测情况下的放弃就意味着重新启动容器。
512520
就绪探测情况下的放弃 Pod 会被打上未就绪的标签。默认值是 3。最小值是 1。
513521

522+
{{< note >}}
514523
<!--
515524
Before Kubernetes 1.20, the field `timeoutSeconds` was not respected for exec probes:
516525
probes continued running indefinitely, even past their configured deadline,
@@ -545,7 +554,7 @@ the process inside the container may keep running even after probe returned fail
545554
当此缺陷被修复之后,在使用 `dockershim` 容器运行时的 Kubernetes `1.20+`
546555
版本中,对于 exec 探针而言,容器中的进程可能会因为超时值的设置保持持续运行,
547556
即使探针返回了失败状态。
548-
557+
{{< /note >}}
549558
{{< caution >}}
550559
<!--
551560
Incorrect implementation of readiness probes may result in an ever growing number
@@ -586,7 +595,7 @@ port to perform the check. The kubelet sends the probe to the pod's IP address,
586595
unless the address is overridden by the optional `host` field in `httpGet`. If
587596
`scheme` field is set to `HTTPS`, the kubelet sends an HTTPS request skipping the
588597
certificate verification. In most scenarios, you do not want to set the `host` field.
589-
Here's one scenario where you would set it. Suppose the Container listens on 127.0.0.1
598+
Here's one scenario where you would set it. Suppose the container listens on 127.0.0.1
590599
and the Pod's `hostNetwork` field is true. Then `host`, under `httpGet`, should be set
591600
to 127.0.0.1. If your pod relies on virtual hosts, which is probably the more common
592601
case, you should not use `host`, but rather set the `Host` header in `httpHeaders`.
@@ -658,6 +667,70 @@ to resolve it.
658667
对于一次 TCP 探测,kubelet 在节点上(不是在 Pod 里面)建立探测连接,
659668
这意味着你不能在 `host` 参数上配置服务名称,因为 kubelet 不能解析服务名称。
660669

670+
<!--
671+
### Probe-level `terminationGracePeriodSeconds`
672+
-->
673+
### 探测器级别 `terminationGracePeriodSeconds`
674+
675+
{{< feature-state for_k8s_version="v1.21" state="alpha" >}}
676+
677+
<!--
678+
Prior to release 1.21, the pod-level `terminationGracePeriodSeconds` was used
679+
for terminating a container that failed its liveness or startup probe. This
680+
coupling was unintended and may have resulted in failed containers taking an
681+
unusually long time to restart when a pod-level `terminationGracePeriodSeconds`
682+
was set.
683+
-->
684+
在 1.21 版之前,pod 级别的 `terminationGracePeriodSeconds` 被用来终止
685+
未能成功处理活跃性探测或启动探测的容器。
686+
这种耦合是意料之外的,可能会导致在设置了 pod 级别的 `terminationGracePeriodSeconds` 后,
687+
需要很长的时间来重新启动失败的容器。
688+
689+
<!--
690+
In 1.21, when the feature flag `ProbeTerminationGracePeriod` is enabled, users
691+
can specify a probe-level `terminationGracePeriodSeconds` as part of the probe
692+
specification. When the feature flag is enabled, and both a pod- and
693+
probe-level `terminationGracePeriodSeconds` are set, the kubelet will use the
694+
probe-level value.
695+
696+
For example,
697+
-->
698+
在1.21中,启用特性标志 `ProbeTerminationGracePeriod` 后,
699+
用户可以指定一个探测器级别的 `terminationGracePeriodSeconds` 作为探测器规格的一部分。
700+
当该特性标志被启用时,若同时设置了 Pod 级别和探测器级别的 `terminationGracePeriodSeconds`,
701+
kubelet 将使用探测器级的值。
702+
703+
例如,
704+
705+
```yaml
706+
spec:
707+
terminationGracePeriodSeconds: 3600 # pod-level
708+
containers:
709+
- name: test
710+
image: ...
711+
712+
ports:
713+
- name: liveness-port
714+
containerPort: 8080
715+
hostPort: 8080
716+
717+
livenessProbe:
718+
httpGet:
719+
path: /healthz
720+
port: liveness-port
721+
failureThreshold: 1
722+
periodSeconds: 60
723+
# Override pod-level terminationGracePeriodSeconds #
724+
terminationGracePeriodSeconds: 60
725+
```
726+
727+
<!--
728+
Probe-level `terminationGracePeriodSeconds` cannot be set for readiness probes.
729+
It will be rejected by the API server.
730+
-->
731+
探测器级别的 `terminationGracePeriodSeconds` 不能用于设置就绪态探针。
732+
它将被 API 服务器拒绝。
733+
661734
## {{% heading "whatsnext" %}}
662735

663736
<!--
@@ -667,13 +740,13 @@ to resolve it.
667740
* 进一步了解[容器探针](/zh/docs/concepts/workloads/pods/pod-lifecycle/#container-probes)。
668741

669742
<!--
670-
### Reference
743+
You can also read the API references for:
671744

672745
* [Pod](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#pod-v1-core)
673746
* [Container](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#container-v1-core)
674747
* [Probe](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#probe-v1-core)
675748
-->
676-
### 参考 {#reference}
749+
你也可以阅读以下的 API 参考资料:
677750

678751
* [Pod](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#pod-v1-core)
679752
* [Container](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#container-v1-core)

0 commit comments

Comments
 (0)