From 77afa1f57b57b348baba803f178fa4b3b97908e0 Mon Sep 17 00:00:00 2001 From: windsonsea Date: Wed, 9 Aug 2023 08:57:38 +0800 Subject: [PATCH] [zh] sync pods-and-endpoint-termination-flow.md --- .../services/connect-applications-service.md | 19 ++++-- .../pods-and-endpoint-termination-flow.md | 60 +++---------------- .../docs/tutorials/services/source-ip.md | 27 ++++++++- .../explore-graceful-termination-nginx.yaml | 11 ++++ 4 files changed, 59 insertions(+), 58 deletions(-) create mode 100644 content/zh-cn/examples/service/explore-graceful-termination-nginx.yaml diff --git a/content/zh-cn/docs/tutorials/services/connect-applications-service.md b/content/zh-cn/docs/tutorials/services/connect-applications-service.md index 57bb46162f..1be3682f11 100644 --- a/content/zh-cn/docs/tutorials/services/connect-applications-service.md +++ b/content/zh-cn/docs/tutorials/services/connect-applications-service.md @@ -55,7 +55,7 @@ Create an nginx Pod, and note that it has a container port specification: 我们在之前的示例中已经做过,然而让我们以网络连接的视角再重做一遍。 创建一个 Nginx Pod,注意其中包含一个容器端口的规约: -{{< codenew file="service/networking/run-my-nginx.yaml" >}} +{{< code file="service/networking/run-my-nginx.yaml" >}} 这等价于使用 `kubectl create -f` 命令及如下的 yaml 文件创建: -{{< codenew file="service/networking/nginx-svc.yaml" >}} +{{< code file="service/networking/nginx-svc.yaml" >}} 以下是你在运行 make 时遇到问题时要遵循的手动步骤(例如,在 Windows 上): + ```shell # 创建公钥和相对应的私钥 openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /d/tmp/nginx.key -out /d/tmp/nginx.crt -subj "/CN=my-nginx/O=my-nginx" @@ -461,7 +470,7 @@ cat /d/tmp/nginx.key | base64 Use the output from the previous commands to create a yaml file as follows. The base64 encoded value should all be on a single line. --> -使用前面命令的输出来创建 yaml 文件,如下所示。 base64 编码的值应全部放在一行上。 +如下所示,使用上述命令的输出来创建 yaml 文件。base64 编码的值应全部放在一行上。 ```yaml apiVersion: "v1" @@ -495,7 +504,7 @@ in the secret, and the Service, to expose both ports (80 and 443): --> 现在修改 Nginx 副本以启动一个使用 Secret 中的证书的 HTTPS 服务器以及相应的用于暴露其端口(80 和 443)的 Service: -{{< codenew file="service/networking/nginx-secure-app.yaml" >}} +{{< code file="service/networking/nginx-secure-app.yaml" >}} -```yaml -apiVersion: apps/v1 -kind: Deployment -metadata: - name: nginx-deployment - labels: - app: nginx -spec: - replicas: 1 - selector: - matchLabels: - app: nginx - template: - metadata: - labels: - app: nginx - spec: - terminationGracePeriodSeconds: 120 # 超长优雅期 - containers: - - name: nginx - image: nginx:latest - ports: - - containerPort: 80 - lifecycle: - preStop: - exec: - # 实际生产环境中的 Pod 终止可能需要执行任何时长,但不会超过 terminationGracePeriodSeconds。 - # 在本例中,只需挂起至少 terminationGracePeriodSeconds 所指定的持续时间, - # 在 120 秒时容器将被强制终止。 - # 请注意,在所有这些时间点 nginx 都将继续处理请求。 - command: [ - "/bin/sh", "-c", "sleep 180" - ] +现在使用以上文件创建 Deployment Pod 和 Service: ---- - -apiVersion: v1 -kind: Service -metadata: - name: nginx-service -spec: - selector: - app: nginx - ports: - - protocol: TCP - port: 80 - targetPort: 80 +```shell +kubectl apply -f pod-with-graceful-termination.yaml +kubectl apply -f explore-graceful-termination-nginx.yaml ``` @@ -222,6 +223,7 @@ You can then run a command inside that Pod: # 从 “kubectl run” 的终端中运行 ip addr ``` + ``` 1: lo: mtu 65536 qdisc noqueue link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 @@ -303,6 +305,7 @@ port allocated above. ```shell for node in $NODES; do curl -s $node:$NODEPORT | grep -i client_address; done ``` + @@ -386,6 +389,7 @@ for node in $NODES; do curl --connect-timeout 1 -s $node:$NODEPORT | grep -i cli The output is similar to: --> 输出类似于: + ``` client_address=198.51.100.79 ``` @@ -447,6 +451,7 @@ kubectl expose deployment source-ip-app --name=loadbalancer --port=80 --target-p The output is: --> 输出为: + ``` service/loadbalancer exposed ``` @@ -455,13 +460,16 @@ service/loadbalancer exposed Print out the IP addresses of the Service: --> 打印 Service 的 IP 地址: + ```console kubectl get svc loadbalancer ``` + 输出类似于: + ``` NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE loadbalancer LoadBalancer 10.0.65.118 203.0.113.140 80/TCP 5m @@ -471,13 +479,16 @@ loadbalancer LoadBalancer 10.0.65.118 203.0.113.140 80/TCP 5m Next, send a request to this Service's external-ip: --> 接下来,发送请求到 Service 的 的外部 IP(External-IP): + ```shell curl 203.0.113.140 ``` + 输出类似于: + ``` CLIENT VALUES: client_address=10.240.0.5 @@ -524,6 +535,7 @@ kubectl get svc loadbalancer -o yaml | grep -i healthCheckNodePort The output is similar to this: --> 输出类似于: + ```yaml healthCheckNodePort: 32122 ``` @@ -542,6 +554,7 @@ kubectl get pod -o wide -l app=source-ip-app The output is similar to this: --> 输出类似于: + ``` NAME READY STATUS RESTARTS AGE IP NODE source-ip-app-826191075-qehz4 1/1 Running 0 20h 10.180.1.136 kubernetes-node-6jst @@ -551,10 +564,15 @@ source-ip-app-826191075-qehz4 1/1 Running 0 20h 10.180. Use `curl` to fetch the `/healthz` endpoint on various nodes: --> 使用 `curl` 获取各个节点上的 `/healthz` 端点: + + ```shell # 在你选择的节点上本地运行 curl localhost:32122/healthz ``` + ``` 1 Service Endpoints found ``` @@ -563,10 +581,15 @@ curl localhost:32122/healthz On a different node you might get a different result: --> 在不同的节点上,你可能会得到不同的结果: + + ```shell # 在你选择的节点上本地运行 curl localhost:32122/healthz ``` + ``` No Service Endpoints Found ``` @@ -586,10 +609,12 @@ then use `curl` to query the IPv4 address of the load balancer: ```shell curl 203.0.113.140 ``` + 输出类似于: + ``` CLIENT VALUES: client_address=198.51.100.79 diff --git a/content/zh-cn/examples/service/explore-graceful-termination-nginx.yaml b/content/zh-cn/examples/service/explore-graceful-termination-nginx.yaml new file mode 100644 index 0000000000..6d1f97a64d --- /dev/null +++ b/content/zh-cn/examples/service/explore-graceful-termination-nginx.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: nginx-service +spec: + selector: + app: nginx + ports: + - protocol: TCP + port: 80 + targetPort: 80 \ No newline at end of file