Skip to content

Commit c89fb16

Browse files
authored
Merge pull request #47362 from windsonsea/probesy
[zh] Sync configure-liveness-readiness-startup-probes.md
2 parents f042fbb + 1fba5d3 commit c89fb16

File tree

2 files changed

+62
-41
lines changed

2 files changed

+62
-41
lines changed

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

Lines changed: 61 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ application more available despite bugs.
2323
-->
2424
这篇文章介绍如何给容器配置存活(Liveness)、就绪(Readiness)和启动(Startup)探针。
2525

26-
有关探针的更多信息,请参阅
27-
[Liveness、Readiness 和 Startup 探针](/zh-cn/docs/concepts/configuration/liveness-readiness-startup-probes)
26+
有关探针的更多信息,
27+
请参阅[存活、就绪和启动探针](/zh-cn/docs/concepts/configuration/liveness-readiness-startup-probes)
2828

2929
[kubelet](/zh-cn/docs/reference/command-line-tools-reference/kubelet/)
3030
使用存活探针来确定什么时候要重启容器。
@@ -291,7 +291,7 @@ checks will fail, and the kubelet will kill and restart the container.
291291
292292
To try the HTTP liveness check, create a Pod:
293293
-->
294-
kubelet 在容器启动之后 3 秒开始执行健康检测。所以前几次健康检查都是成功的。
294+
kubelet 在容器启动之后 3 秒开始执行健康检查。所以前几次健康检查都是成功的。
295295
但是 10 秒之后,健康检查会失败,并且 kubelet 会杀死容器再重新启动容器。
296296

297297
创建一个 Pod 来测试 HTTP 的存活检测:
@@ -334,29 +334,34 @@ can't it is considered a failure.
334334

335335
<!--
336336
As you can see, configuration for a TCP check is quite similar to an HTTP check.
337-
This example uses both readiness and liveness probes. The kubelet will send the
338-
first readiness probe 15 seconds after the container starts. This will attempt to
339-
connect to the `goproxy` container on port 8080. If the probe succeeds, the Pod
340-
will be marked as ready. The kubelet will continue to run this check every 10
341-
seconds.
342-
343-
In addition to the readiness probe, this configuration includes a liveness probe.
344-
The kubelet will run the first liveness probe 15 seconds after the container
345-
starts. Similar to the readiness probe, this will attempt to connect to the
346-
`goproxy` container on port 8080. If the liveness probe fails, the container
347-
will be restarted.
337+
This example uses both readiness and liveness probes. The kubelet will run the
338+
first liveness probe 15 seconds after the container starts. This will attempt to
339+
connect to the `goproxy` container on port 8080. If the liveness probe fails,
340+
the container will be restarted. The kubelet will continue to run this check
341+
every 10 seconds.
342+
-->
343+
如你所见,TCP 检测的配置和 HTTP 检测非常相似。
344+
下面这个例子同时使用就绪探针和存活探针。kubelet 会在容器启动 15 秒后运行第一次存活探测。
345+
此探测会尝试连接 `goproxy` 容器的 8080 端口。
346+
如果此存活探测失败,容器将被重启。kubelet 将继续每隔 10 秒运行一次这种探测。
347+
348+
<!--
349+
In addition to the liveness probe, this configuration includes a readiness
350+
probe. The kubelet will run the first readiness probe 15 seconds after the
351+
container starts. Similar to the liveness probe, this will attempt to connect to
352+
the `goproxy` container on port 8080. If the probe succeeds, the Pod will be
353+
marked as ready and will receive traffic from services. If the readiness probe
354+
fails, the pod will be marked unready and will not receive traffic from any
355+
services.
348356
349357
To try the TCP liveness check, create a Pod:
350358
-->
351-
如你所见,TCP 检测的配置和 HTTP 检测非常相似
352-
下面这个例子同时使用就绪和存活探针。kubelet 会在容器启动 15 秒后发送第一个就绪探针
353-
探针会尝试连接 `goproxy` 容器的 8080 端口。
354-
如果探测成功,这个 Pod 会被标记为就绪状态,kubelet 将继续每隔 10 秒运行一次探测
359+
除了存活探针,这个配置还包括一个就绪探针
360+
kubelet 会在容器启动 15 秒后运行第一次就绪探测
361+
与存活探测类似,就绪探测会尝试连接 `goproxy` 容器的 8080 端口。
362+
如果就绪探测失败,Pod 将被标记为未就绪,且不会接收来自任何服务的流量
355363

356-
除了就绪探针,这个配置包括了一个存活探针。
357-
kubelet 会在容器启动 15 秒后进行第一次存活探测。
358-
与就绪探针类似,存活探针会尝试连接 `goproxy` 容器的 8080 端口。
359-
如果存活探测失败,容器会被重新启动。
364+
要尝试 TCP 存活检测,运行以下命令创建 Pod:
360365

361366
```shell
362367
kubectl apply -f https://k8s.io/examples/pods/probe/tcp-liveness-readiness.yaml
@@ -365,7 +370,7 @@ kubectl apply -f https://k8s.io/examples/pods/probe/tcp-liveness-readiness.yaml
365370
<!--
366371
After 15 seconds, view Pod events to verify that liveness probes:
367372
-->
368-
15 秒之后,通过看 Pod 事件来检测存活探针:
373+
15 秒之后,通过查看 Pod 事件来检测存活探针:
369374

370375
```shell
371376
kubectl describe pod goproxy
@@ -388,11 +393,6 @@ Here is an example manifest:
388393
-->
389394
如果你的应用实现了
390395
[gRPC 健康检查协议](https://github.com/grpc/grpc/blob/master/doc/health-checking.md)
391-
kubelet 可以配置为使用该协议来执行应用存活性检查。
392-
你必须启用 `GRPCContainerProbe`
393-
[特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/)
394-
才能配置依赖于 gRPC 的检查机制。
395-
396396
这个例子展示了如何配置 Kubernetes 以将其用于应用的存活性检查。
397397
类似地,你可以配置就绪探针和启动探针。
398398

@@ -422,10 +422,10 @@ those. For example: `myservice-liveness` (using `-` as a separator).
422422

423423
{{< note >}}
424424
<!--
425-
Unlike HTTP and TCP probes, you cannot specify the health check port by name, and you
425+
Unlike HTTP or TCP probes, you cannot specify the health check port by name, and you
426426
cannot configure a custom hostname.
427427
-->
428-
与 HTTP TCP 探针不同,gRPC 探测不能使用按名称指定端口
428+
与 HTTP TCP 探针不同,gRPC 探测不能按名称指定健康检查端口
429429
也不能自定义主机名。
430430
{{< /note >}}
431431

@@ -501,21 +501,20 @@ livenessProbe:
501501
<!--
502502
## Protect slow starting containers with startup probes {#define-startup-probes}
503503
504-
Sometimes, you have to deal with legacy applications that might require
505-
an additional startup time on their first initialization.
506-
In such cases, it can be tricky to set up liveness probe parameters without
507-
compromising the fast response to deadlocks that motivated such a probe.
508-
The trick is to set up a startup probe with the same command, HTTP or TCP
509-
check, with a `failureThreshold * periodSeconds` long enough to cover the
510-
worst case startup time.
504+
Sometimes, you have to deal with applications that require additional startup
505+
time on their first initialization. In such cases, it can be tricky to set up
506+
liveness probe parameters without compromising the fast response to deadlocks
507+
that motivated such a probe. The solution is to set up a startup probe with the
508+
same command, HTTP or TCP check, with a `failureThreshold * periodSeconds` long
509+
enough to cover the worst case startup time.
511510

512511
So, the previous example would become:
513512
-->
514513
## 使用启动探针保护慢启动容器 {#define-startup-probes}
515514

516515
有时候,会有一些现有的应用在启动时需要较长的初始化时间。
517-
要这种情况下,若要不影响对死锁作出快速响应的探测,设置存活探测参数是要技巧的。
518-
技巧就是使用相同的命令来设置启动探测,针对 HTTP 或 TCP 检测,可以通过将
516+
在这种情况下,若要不影响对死锁作出快速响应的探测,设置存活探测参数是要技巧的。
517+
解决办法是使用相同的命令来设置启动探测,针对 HTTP 或 TCP 检测,可以通过将
519518
`failureThreshold * periodSeconds` 参数设置为足够长的时间来应对最糟糕情况下的启动时间。
520519

521520
这样,前面的例子就变成了:
@@ -639,7 +638,7 @@ liveness and readiness checks:
639638
* `initialDelaySeconds`: Number of seconds after the container has started before startup,
640639
liveness or readiness probes are initiated. If a startup probe is defined, liveness and
641640
readiness probe delays do not begin until the startup probe has succeeded. If the value of
642-
`periodSeconds` is greater than `initialDelaySeconds` then the `initialDelaySeconds` would be
641+
`periodSeconds` is greater than `initialDelaySeconds` then the `initialDelaySeconds` will be
643642
ignored. Defaults to 0 seconds. Minimum value is 0.
644643
* `periodSeconds`: How often (in seconds) to perform the probe. Default to 10 seconds.
645644
The minimum value is 1.
@@ -878,6 +877,28 @@ For example:
878877
-->
879878
例如:
880879

880+
<!--
881+
```yaml
882+
spec:
883+
terminationGracePeriodSeconds: 3600 # pod-level
884+
containers:
885+
- name: test
886+
image: ...
887+
888+
ports:
889+
- name: liveness-port
890+
containerPort: 8080
891+
892+
livenessProbe:
893+
httpGet:
894+
path: /healthz
895+
port: liveness-port
896+
failureThreshold: 1
897+
periodSeconds: 60
898+
# Override pod-level terminationGracePeriodSeconds #
899+
terminationGracePeriodSeconds: 60
900+
```
901+
-->
881902
```yaml
882903
spec:
883904
terminationGracePeriodSeconds: 3600 # Pod 级别设置

content/zh-cn/examples/pods/probe/tcp-liveness-readiness.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ spec:
1919
tcpSocket:
2020
port: 8080
2121
initialDelaySeconds: 15
22-
periodSeconds: 20
22+
periodSeconds: 10

0 commit comments

Comments
 (0)