Skip to content

Commit a339509

Browse files
authored
Merge pull request #42464 from windsonsea/podflow
[zh] sync pods-and-endpoint-termination-flow.md and 2 service tutorials
2 parents 3570f4c + 77afa1f commit a339509

File tree

4 files changed

+59
-58
lines changed

4 files changed

+59
-58
lines changed

content/zh-cn/docs/tutorials/services/connect-applications-service.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Create an nginx Pod, and note that it has a container port specification:
5555
我们在之前的示例中已经做过,然而让我们以网络连接的视角再重做一遍。
5656
创建一个 Nginx Pod,注意其中包含一个容器端口的规约:
5757

58-
{{< codenew file="service/networking/run-my-nginx.yaml" >}}
58+
{{< code file="service/networking/run-my-nginx.yaml" >}}
5959

6060
<!--
6161
This makes it accessible from any node in your cluster. Check the nodes the Pod is running on:
@@ -149,7 +149,7 @@ This is equivalent to `kubectl apply -f` the following yaml:
149149
-->
150150
这等价于使用 `kubectl create -f` 命令及如下的 yaml 文件创建:
151151
152-
{{< codenew file="service/networking/nginx-svc.yaml" >}}
152+
{{< code file="service/networking/nginx-svc.yaml" >}}
153153
154154
<!--
155155
This specification will create a Service which targets TCP port 80 on any Pod
@@ -449,6 +449,15 @@ Following are the manual steps to follow in case you run into problems running m
449449
-->
450450
以下是你在运行 make 时遇到问题时要遵循的手动步骤(例如,在 Windows 上):
451451
452+
<!--
453+
```shell
454+
# Create a public private key pair
455+
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"
456+
# Convert the keys to base64 encoding
457+
cat /d/tmp/nginx.crt | base64
458+
cat /d/tmp/nginx.key | base64
459+
```
460+
-->
452461
```shell
453462
# 创建公钥和相对应的私钥
454463
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
461470
Use the output from the previous commands to create a yaml file as follows.
462471
The base64 encoded value should all be on a single line.
463472
-->
464-
使用前面命令的输出来创建 yaml 文件,如下所示。 base64 编码的值应全部放在一行上。
473+
如下所示,使用上述命令的输出来创建 yaml 文件base64 编码的值应全部放在一行上。
465474
466475
```yaml
467476
apiVersion: "v1"
@@ -495,7 +504,7 @@ in the secret, and the Service, to expose both ports (80 and 443):
495504
-->
496505
现在修改 Nginx 副本以启动一个使用 Secret 中的证书的 HTTPS 服务器以及相应的用于暴露其端口(80 和 443)的 Service:
497506
498-
{{< codenew file="service/networking/nginx-secure-app.yaml" >}}
507+
{{< code file="service/networking/nginx-secure-app.yaml" >}}
499508
500509
<!--
501510
Noteworthy points about the nginx-secure-app manifest:
@@ -548,7 +557,7 @@ for simplicity, the pod only needs nginx.crt to access the Service):
548557
通过创建 Service,我们连接了在证书中的 CName 与在 Service 查询时被 Pod 使用的实际 DNS 名字。
549558
让我们从一个 Pod 来测试(为了方便,这里使用同一个 Secret,Pod 仅需要使用 nginx.crt 去访问 Service):
550559
551-
{{< codenew file="service/networking/curlpod.yaml" >}}
560+
{{< code file="service/networking/curlpod.yaml" >}}
552561
553562
```shell
554563
kubectl apply -f ./curlpod.yaml

content/zh-cn/docs/tutorials/services/pods-and-endpoint-termination-flow.md

Lines changed: 8 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -61,62 +61,18 @@ Let's say you have a Deployment containing of a single `nginx` replica
6161

6262
假设你有包含单个 nginx 副本(仅用于演示目的)的一个 Deployment 和一个 Service:
6363

64-
{{< codenew file="service/pod-with-graceful-termination.yaml" >}}
64+
{{% code file="service/pod-with-graceful-termination.yaml" %}}
65+
66+
{{% code file="service/explore-graceful-termination-nginx.yaml" %}}
6567

6668
<!--
67-
# extra long grace period
68-
# Real life termination may take any time up to terminationGracePeriodSeconds.
69-
# In this example - just hang around for at least the duration of terminationGracePeriodSeconds,
70-
# at 120 seconds container will be forcibly terminated.
71-
# Note, all this time nginx will keep processing requests.
69+
Now create the Deployment Pod and Service using the above files:
7270
-->
73-
```yaml
74-
apiVersion: apps/v1
75-
kind: Deployment
76-
metadata:
77-
name: nginx-deployment
78-
labels:
79-
app: nginx
80-
spec:
81-
replicas: 1
82-
selector:
83-
matchLabels:
84-
app: nginx
85-
template:
86-
metadata:
87-
labels:
88-
app: nginx
89-
spec:
90-
terminationGracePeriodSeconds: 120 # 超长优雅期
91-
containers:
92-
- name: nginx
93-
image: nginx:latest
94-
ports:
95-
- containerPort: 80
96-
lifecycle:
97-
preStop:
98-
exec:
99-
# 实际生产环境中的 Pod 终止可能需要执行任何时长,但不会超过 terminationGracePeriodSeconds。
100-
# 在本例中,只需挂起至少 terminationGracePeriodSeconds 所指定的持续时间,
101-
# 在 120 秒时容器将被强制终止。
102-
# 请注意,在所有这些时间点 nginx 都将继续处理请求。
103-
command: [
104-
"/bin/sh", "-c", "sleep 180"
105-
]
106-
107-
---
71+
现在使用以上文件创建 Deployment Pod 和 Service:
10872

109-
apiVersion: v1
110-
kind: Service
111-
metadata:
112-
name: nginx-service
113-
spec:
114-
selector:
115-
app: nginx
116-
ports:
117-
- protocol: TCP
118-
port: 80
119-
targetPort: 80
73+
```shell
74+
kubectl apply -f pod-with-graceful-termination.yaml
75+
kubectl apply -f explore-graceful-termination-nginx.yaml
12076
```
12177

12278
<!--

content/zh-cn/docs/tutorials/services/source-ip.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: 使用源 IP
33
content_type: tutorial
44
min-kubernetes-server-version: v1.5
5-
weight: 10
5+
weight: 40
66
---
77
<!--
88
title: Using Source IP
@@ -154,6 +154,7 @@ Get the proxy mode on one of the nodes (kube-proxy listens on port 10249):
154154
# 在要查询的节点上的 Shell 中运行
155155
curl http://localhost:10249/proxyMode
156156
```
157+
157158
<!--
158159
The output is:
159160
-->
@@ -222,6 +223,7 @@ You can then run a command inside that Pod:
222223
# 从 “kubectl run” 的终端中运行
223224
ip addr
224225
```
226+
225227
```
226228
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue
227229
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
@@ -303,6 +305,7 @@ port allocated above.
303305
```shell
304306
for node in $NODES; do curl -s $node:$NODEPORT | grep -i client_address; done
305307
```
308+
306309
<!--
307310
The output is similar to:
308311
-->
@@ -386,6 +389,7 @@ for node in $NODES; do curl --connect-timeout 1 -s $node:$NODEPORT | grep -i cli
386389
The output is similar to:
387390
-->
388391
输出类似于:
392+
389393
```
390394
client_address=198.51.100.79
391395
```
@@ -447,6 +451,7 @@ kubectl expose deployment source-ip-app --name=loadbalancer --port=80 --target-p
447451
The output is:
448452
-->
449453
输出为:
454+
450455
```
451456
service/loadbalancer exposed
452457
```
@@ -455,13 +460,16 @@ service/loadbalancer exposed
455460
Print out the IP addresses of the Service:
456461
-->
457462
打印 Service 的 IP 地址:
463+
458464
```console
459465
kubectl get svc loadbalancer
460466
```
467+
461468
<!--
462469
The output is similar to this:
463470
-->
464471
输出类似于:
472+
465473
```
466474
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
467475
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
471479
Next, send a request to this Service's external-ip:
472480
-->
473481
接下来,发送请求到 Service 的 的外部 IP(External-IP):
482+
474483
```shell
475484
curl 203.0.113.140
476485
```
486+
477487
<!--
478488
The output is similar to this:
479489
-->
480490
输出类似于:
491+
481492
```
482493
CLIENT VALUES:
483494
client_address=10.240.0.5
@@ -524,6 +535,7 @@ kubectl get svc loadbalancer -o yaml | grep -i healthCheckNodePort
524535
The output is similar to this:
525536
-->
526537
输出类似于:
538+
527539
```yaml
528540
healthCheckNodePort: 32122
529541
```
@@ -542,6 +554,7 @@ kubectl get pod -o wide -l app=source-ip-app
542554
The output is similar to this:
543555
-->
544556
输出类似于:
557+
545558
```
546559
NAME READY STATUS RESTARTS AGE IP NODE
547560
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.
551564
Use `curl` to fetch the `/healthz` endpoint on various nodes:
552565
-->
553566
使用 `curl` 获取各个节点上的 `/healthz` 端点:
567+
568+
<!--
569+
# Run this locally on a node you choose
570+
-->
554571
```shell
555572
# 在你选择的节点上本地运行
556573
curl localhost:32122/healthz
557574
```
575+
558576
```
559577
1 Service Endpoints found
560578
```
@@ -563,10 +581,15 @@ curl localhost:32122/healthz
563581
On a different node you might get a different result:
564582
-->
565583
在不同的节点上,你可能会得到不同的结果:
584+
585+
<!--
586+
# Run this locally on a node you choose
587+
-->
566588
```shell
567589
# 在你选择的节点上本地运行
568590
curl localhost:32122/healthz
569591
```
592+
570593
```
571594
No Service Endpoints Found
572595
```
@@ -586,10 +609,12 @@ then use `curl` to query the IPv4 address of the load balancer:
586609
```shell
587610
curl 203.0.113.140
588611
```
612+
589613
<!--
590614
The output is similar to this:
591615
-->
592616
输出类似于:
617+
593618
```
594619
CLIENT VALUES:
595620
client_address=198.51.100.79
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: nginx-service
5+
spec:
6+
selector:
7+
app: nginx
8+
ports:
9+
- protocol: TCP
10+
port: 80
11+
targetPort: 80

0 commit comments

Comments
 (0)