Skip to content

Commit aae1ca4

Browse files
Xunzhuotengqm
andauthored
Sync with English version and Update Deprecated URL (#26692)
* Update deprecated URL: Proxy http://www.haproxy.org/download/1.5/doc/proxy-protocol.txt is deprecated and 403 Forbidden,change it to https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt * Sync with English version and Update Deprecated URL * Sync with english version and update URL * Update source-ip.md * Update source-ip.md * Update content/zh/docs/tutorials/services/source-ip.md Co-authored-by: Qiming Teng <[email protected]> * Update content/zh/docs/tutorials/services/source-ip.md Co-authored-by: Qiming Teng <[email protected]> * Update content/zh/docs/tutorials/services/source-ip.md Co-authored-by: Qiming Teng <[email protected]> * Update content/zh/docs/tutorials/services/source-ip.md Co-authored-by: Qiming Teng <[email protected]> Co-authored-by: Qiming Teng <[email protected]>
1 parent b8616ed commit aae1ca4

File tree

1 file changed

+46
-40
lines changed

1 file changed

+46
-40
lines changed

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

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,23 @@ clusterip ClusterIP 10.0.170.92 <none> 80/TCP 51s
103103

104104
从相同集群中的一个 pod 访问这个 `ClusterIP`
105105

106-
```console
106+
```shell
107107
kubectl run busybox -it --image=busybox --restart=Never --rm
108108
```
109109
输出结果与以下结果类似:
110110
```
111111
Waiting for pod default/busybox to be running, status is Pending, pod ready: false
112112
If you don't see a command prompt, try pressing enter.
113+
```
114+
115+
然后你可以在 Pod 内运行命令:
113116

114-
# ip addr
117+
```shell
118+
# 在终端内使用"kubectl run"执行
119+
120+
ip addr
121+
```
122+
```
115123
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue
116124
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
117125
inet 127.0.0.1/8 scope host lo
@@ -124,8 +132,15 @@ If you don't see a command prompt, try pressing enter.
124132
valid_lft forever preferred_lft forever
125133
inet6 fe80::188a:84ff:feb0:26a5/64 scope link
126134
valid_lft forever preferred_lft forever
135+
```
136+
137+
然后使用 `wget` 去请求本地 Web 服务器
138+
```shell
139+
# 用名为 "clusterip" 的服务的 IPv4 地址替换 "10.0.170.92"
127140

128-
# wget -qO - 10.0.170.92
141+
wget -qO - 10.0.170.92
142+
```
143+
```
129144
CLIENT VALUES:
130145
client_address=10.244.3.8
131146
command=GET
@@ -178,17 +193,19 @@ client_address=10.240.0.3
178193

179194
用图表示:
180195

181-
```
182-
client
183-
\ ^
184-
\ \
185-
v \
186-
node 1 <--- node 2
187-
| ^ SNAT
188-
| | --->
189-
v |
190-
endpoint
191-
```
196+
{{< mermaid >}}
197+
graph LR;
198+
client(client)-->node2[节点 2];
199+
node2-->client;
200+
node2-. SNAT .->node1[节点 1];
201+
node1-. SNAT .->node2;
202+
node1-->endpoint(端点);
203+
204+
classDef plain fill:#ddd,stroke:#fff,stroke-width:4px,color:#000;
205+
classDef k8s fill:#326ce5,stroke:#fff,stroke-width:4px,color:#fff;
206+
class node1,node2,endpoint k8s;
207+
class client plain;
208+
{{</ mermaid >}}
192209

193210

194211
为了防止这种情况发生,Kubernetes 提供了一个特性来保留客户端的源 IP 地址[(点击此处查看可用特性)](/zh/docs/tasks/access-application-cluster/create-external-load-balancer/#preserving-the-client-source-ip)。设置 `service.spec.externalTrafficPolicy` 的值为 `Local`,请求就只会被代理到本地 endpoints 而不会被转发到其它节点。这样就保留了最初的源 IP 地址。如果没有本地 endpoints,发送到这个节点的数据包将会被丢弃。这样在应用到数据包的任何包处理规则下,你都能依赖这个正确的 source-ip 使数据包通过并到达 endpoint。
@@ -229,17 +246,18 @@ client_address=104.132.1.79
229246

230247
用图表示:
231248

232-
```
233-
client
234-
^ / \
235-
/ / \
236-
/ v X
237-
node 1 node 2
238-
^ |
239-
| |
240-
| v
241-
endpoint
242-
```
249+
{{< mermaid >}}
250+
graph TD;
251+
client --> node1[节点 1];
252+
client(client) --x node2[节点 2];
253+
node1 --> endpoint(端点);
254+
endpoint --> node1;
255+
256+
classDef plain fill:#ddd,stroke:#fff,stroke-width:4px,color:#000;
257+
classDef k8s fill:#326ce5,stroke:#fff,stroke-width:4px,color:#fff;
258+
class node1,node2,endpoint k8s;
259+
class client plain;
260+
{{</ mermaid >}}
243261

244262

245263

@@ -285,17 +303,7 @@ client_address=10.240.0.5
285303

286304
用图表示:
287305

288-
```
289-
client
290-
|
291-
lb VIP
292-
/ ^
293-
v /
294-
health check ---> node 1 node 2 <--- health check
295-
200 <--- ^ | ---> 500
296-
| V
297-
endpoint
298-
```
306+
![Source IP with externalTrafficPolicy](/images/docs/sourceip-externaltrafficpolicy.svg)
299307

300308

301309
你可以设置 annotation 来进行测试:
@@ -367,7 +375,7 @@ __跨平台支持__
367375
2. 使用一个包转发器,因此从客户端发送到负载均衡器 VIP 的请求在拥有客户端源 IP 地址的节点终止,而不被中间代理。
368376

369377

370-
第一类负载均衡器必须使用一种它和后端之间约定的协议来和真实的客户端 IP 通信,例如 HTTP [X-FORWARDED-FOR](https://en.wikipedia.org/wiki/X-Forwarded-For) 头,或者 [proxy 协议](http://www.haproxy.org/download/1.5/doc/proxy-protocol.txt)
378+
第一类负载均衡器必须使用一种它和后端之间约定的协议来和真实的客户端 IP 通信,例如 HTTP [X-FORWARDED-FOR](https://en.wikipedia.org/wiki/X-Forwarded-For) 头,或者 [proxy 协议](https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt)
371379
第二类负载均衡器可以通过简单的在保存于 Service 的 `service.spec.healthCheckNodePort` 字段上创建一个 HTTP 健康检查点来使用上面描述的特性。
372380

373381

@@ -394,6 +402,4 @@ $ kubectl delete deployment source-ip-app
394402
## {{% heading "whatsnext" %}}
395403

396404

397-
* 学习更多关于 [通过 services 连接应用](/zh/docs/concepts/services-networking/connect-applications-service/)
398-
* 学习更多关于 [负载均衡](/zh/docs/user-guide/load-balancer)
399-
405+
* 进一步学习 [通过 services 连接应用](/zh/docs/concepts/services-networking/connect-applications-service/)

0 commit comments

Comments
 (0)