@@ -23,8 +23,8 @@ application more available despite bugs.
23
23
-->
24
24
这篇文章介绍如何给容器配置存活(Liveness)、就绪(Readiness)和启动(Startup)探针。
25
25
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 ) 。
28
28
29
29
[ kubelet] ( /zh-cn/docs/reference/command-line-tools-reference/kubelet/ )
30
30
使用存活探针来确定什么时候要重启容器。
@@ -291,7 +291,7 @@ checks will fail, and the kubelet will kill and restart the container.
291
291
292
292
To try the HTTP liveness check, create a Pod:
293
293
-->
294
- kubelet 在容器启动之后 3 秒开始执行健康检测 。所以前几次健康检查都是成功的。
294
+ kubelet 在容器启动之后 3 秒开始执行健康检查 。所以前几次健康检查都是成功的。
295
295
但是 10 秒之后,健康检查会失败,并且 kubelet 会杀死容器再重新启动容器。
296
296
297
297
创建一个 Pod 来测试 HTTP 的存活检测:
@@ -334,29 +334,34 @@ can't it is considered a failure.
334
334
335
335
<!--
336
336
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.
348
356
349
357
To try the TCP liveness check, create a Pod:
350
358
-->
351
- 如你所见,TCP 检测的配置和 HTTP 检测非常相似 。
352
- 下面这个例子同时使用就绪和存活探针。 kubelet 会在容器启动 15 秒后发送第一个就绪探针 。
353
- 探针会尝试连接 ` goproxy ` 容器的 8080 端口。
354
- 如果探测成功,这个 Pod 会被标记为就绪状态,kubelet 将继续每隔 10 秒运行一次探测 。
359
+ 除了存活探针,这个配置还包括一个就绪探针 。
360
+ kubelet 会在容器启动 15 秒后运行第一次就绪探测 。
361
+ 与存活探测类似,就绪探测会尝试连接 ` goproxy ` 容器的 8080 端口。
362
+ 如果就绪探测失败, Pod 将被标记为未就绪,且不会接收来自任何服务的流量 。
355
363
356
- 除了就绪探针,这个配置包括了一个存活探针。
357
- kubelet 会在容器启动 15 秒后进行第一次存活探测。
358
- 与就绪探针类似,存活探针会尝试连接 ` goproxy ` 容器的 8080 端口。
359
- 如果存活探测失败,容器会被重新启动。
364
+ 要尝试 TCP 存活检测,运行以下命令创建 Pod:
360
365
361
366
``` shell
362
367
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
365
370
<!--
366
371
After 15 seconds, view Pod events to verify that liveness probes:
367
372
-->
368
- 15 秒之后,通过看 Pod 事件来检测存活探针:
373
+ 15 秒之后,通过查看 Pod 事件来检测存活探针:
369
374
370
375
``` shell
371
376
kubectl describe pod goproxy
@@ -388,11 +393,6 @@ Here is an example manifest:
388
393
-->
389
394
如果你的应用实现了
390
395
[ 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
-
396
396
这个例子展示了如何配置 Kubernetes 以将其用于应用的存活性检查。
397
397
类似地,你可以配置就绪探针和启动探针。
398
398
@@ -422,10 +422,10 @@ those. For example: `myservice-liveness` (using `-` as a separator).
422
422
423
423
{{< note >}}
424
424
<!--
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
426
426
cannot configure a custom hostname.
427
427
-->
428
- 与 HTTP 和 TCP 探针不同,gRPC 探测不能使用按名称指定端口 ,
428
+ 与 HTTP 或 TCP 探针不同,gRPC 探测不能按名称指定健康检查端口 ,
429
429
也不能自定义主机名。
430
430
{{< /note >}}
431
431
@@ -501,21 +501,20 @@ livenessProbe:
501
501
<!--
502
502
## Protect slow starting containers with startup probes {#define-startup-probes}
503
503
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.
511
510
512
511
So, the previous example would become :
513
512
-->
514
513
# # 使用启动探针保护慢启动容器 {#define-startup-probes}
515
514
516
515
有时候,会有一些现有的应用在启动时需要较长的初始化时间。
517
- 要这种情况下 ,若要不影响对死锁作出快速响应的探测,设置存活探测参数是要技巧的。
518
- 技巧就是使用相同的命令来设置启动探测 ,针对 HTTP 或 TCP 检测,可以通过将
516
+ 在这种情况下 ,若要不影响对死锁作出快速响应的探测,设置存活探测参数是要技巧的。
517
+ 解决办法是使用相同的命令来设置启动探测 ,针对 HTTP 或 TCP 检测,可以通过将
519
518
` failureThreshold * periodSeconds` 参数设置为足够长的时间来应对最糟糕情况下的启动时间。
520
519
521
520
这样,前面的例子就变成了:
@@ -639,7 +638,7 @@ liveness and readiness checks:
639
638
* `initialDelaySeconds`: Number of seconds after the container has started before startup,
640
639
liveness or readiness probes are initiated. If a startup probe is defined, liveness and
641
640
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
643
642
ignored. Defaults to 0 seconds. Minimum value is 0.
644
643
* `periodSeconds`: How often (in seconds) to perform the probe. Default to 10 seconds.
645
644
The minimum value is 1.
@@ -878,6 +877,28 @@ For example:
878
877
-->
879
878
例如:
880
879
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
+ -->
881
902
` ` ` yaml
882
903
spec:
883
904
terminationGracePeriodSeconds: 3600 # Pod 级别设置
0 commit comments