1
1
---
2
- title : 服务拓扑(Service Topology)
3
- feature :
4
- title : 服务拓扑(Service Topology)
5
- description : >
6
- 基于集群拓扑的服务流量路由。
7
-
2
+ title : 使用拓扑键实现拓扑感知的流量路由
8
3
content_type : concept
9
4
weight : 10
10
5
---
11
6
<!--
12
7
reviewers:
13
8
- johnbelamaric
14
9
- imroc
15
- title: Service Topology
16
- feature:
17
- title: Service Topology
18
- description: >
19
- Routing of service traffic based upon cluster topology.
20
-
10
+ title: Topology-aware traffic routing with topology keys
21
11
content_type: concept
22
12
weight: 10
23
13
-->
24
14
25
15
<!-- overview -->
26
16
27
- {{< feature-state for_k8s_version="v1.17" state="alpha" >}}
17
+ {{< feature-state for_k8s_version="v1.21" state="deprecated" >}}
18
+
19
+ {{< note >}}
20
+ <!--
21
+ This feature, specifically the alpha `topologyKeys` API, is deprecated since
22
+ Kubernetes v1.21.
23
+ [Topology Aware Hints](/docs/concepts/services-networking/topology-aware-hints/),
24
+ introduced in Kubernetes v1.21, provide similar functionality.
25
+ -->
26
+ 此功能特性,尤其是 Alpha 阶段的 ` topologyKeys ` API,在 Kubernetes v1.21
27
+ 版本中已被废弃。Kubernetes v1.21 版本中引入的
28
+ [ 拓扑感知的提示] ( /zh/docs/concepts/services-networking/topology-aware-hints/ ) ,
29
+ 提供类似的功能。
30
+ {{</ note >}}
28
31
29
32
<!--
30
33
_Service Topology_ enables a service to route traffic based upon the Node
@@ -38,53 +41,58 @@ in the same availability zone.
38
41
<!-- body -->
39
42
40
43
<!--
41
- ## Introduction
44
+ ## Topology-aware traffic routing
42
45
43
46
By default, traffic sent to a `ClusterIP` or `NodePort` Service may be routed to
44
- any backend address for the Service. Since Kubernetes 1.7 it has been possible
45
- to route "external" traffic to the Pods running on the Node that received the
46
- traffic, but this is not supported for `ClusterIP` Services, and more complex
47
- topologies — such as routing zonally — have not been possible. The
48
- _Service Topology_ feature resolves this by allowing the Service creator to
49
- define a policy for routing traffic based upon the Node labels for the
50
- originating and destination Nodes.
51
-
52
- By using Node label matching between the source and destination, the operator
53
- may designate groups of Nodes that are "closer" and "farther" from one another,
54
- using whatever metric makes sense for that operator's requirements. For many
55
- operators in public clouds, for example, there is a preference to keep service
56
- traffic within the same zone, because interzonal traffic has a cost associated
57
- with it, while intrazonal traffic does not. Other common needs include being able
58
- to route traffic to a local Pod managed by a DaemonSet, or keeping traffic to
59
- Nodes connected to the same top-of-rack switch for the lowest latency.
47
+ any backend address for the Service. Kubernetes 1.7 made it possible to
48
+ route "external" traffic to the Pods running on the same Node that received the
49
+ traffic. For `ClusterIP` Services, the equivalent same-node preference for
50
+ routing wasn't possible; nor could you configure your cluster to favor routing
51
+ to endpoints within the same zone.
52
+ By setting `topologyKeys` on a Service, you're able to define a policy for routing
53
+ traffic based upon the Node labels for the originating and destination Nodes.
60
54
-->
61
- ## 介绍 {#introduction}
55
+ ## 拓扑感知的流量路由
62
56
63
- 默认情况下,发往 ` ClusterIP ` 或者 ` NodePort ` 服务的流量可能会被路由到任意一个服务后端的地址上。
64
- 从 Kubernetes 1.7 开始,可以将“外部”流量路由到节点上运行的 Pod 上,但不支持 ` ClusterIP ` 服务,
65
- 更复杂的拓扑 &mdash ; 比如分区路由 &mdash ; 也还不支持。
66
- 通过允许 ` Service ` 创建者根据源 ` Node ` 和目的 ` Node ` 的标签来定义流量路由策略,
67
- 服务拓扑特性实现了服务流量的路由。
57
+ 默认情况下,发往 ` ClusterIP ` 或者 ` NodePort ` 服务的流量可能会被路由到
58
+ 服务的任一后端的地址。Kubernetes 1.7 允许将“外部”流量路由到接收到流量的
59
+ 节点上的 Pod。对于 ` ClusterIP ` 服务,无法完成同节点优先的路由,你也无法
60
+ 配置集群优选路由到同一可用区中的端点。
61
+ 通过在 Service 上配置 ` topologyKeys ` ,你可以基于来源节点和目标节点的
62
+ 标签来定义流量路由策略。
68
63
69
- 通过对源 ` Node ` 和目的 ` Node ` 标签的匹配,运营者可以使用任何符合运营者要求的度量值
70
- 来指定彼此“较近”和“较远”的节点组。
71
- 例如,对于在公有云上的运营者来说,更偏向于把流量控制在同一区域内,
72
- 因为区域间的流量是有费用成本的,而区域内的流量没有。
73
- 其它常用需求还包括把流量路由到由 ` DaemonSet ` 管理的本地 Pod 上,或者
74
- 把保持流量在连接同一机架交换机的 ` Node ` 上,以获得低延时。
64
+ <!--
65
+ The label matching between the source and destination lets you, as a cluster
66
+ operator, designate sets of Nodes that are "closer" and "farther" from one another.
67
+ You can define labels to represent whatever metric makes sense for your own
68
+ requirements.
69
+ In public clouds, for example, you might prefer to keep network traffic within the
70
+ same zone, because interzonal traffic has a cost associated with it (and intrazonal
71
+ traffic typically does not). Other common needs include being able to route traffic
72
+ to a local Pod managed by a DaemonSet, or directing traffic to Nodes connected to the
73
+ same top-of-rack switch for the lowest latency.
74
+ -->
75
+ 通过对源和目的之间的标签匹配,作为集群操作者的你可以根据节点间彼此“较近”和“较远”
76
+ 来定义节点集合。你可以基于符合自身需求的任何度量值来定义标签。
77
+ 例如,在公有云上,你可能更偏向于把流量控制在同一区内,因为区间流量是有费用成本的,
78
+ 而区内流量则没有。
79
+ 其它常见需求还包括把流量路由到由 ` DaemonSet ` 管理的本地 Pod 上,或者
80
+ 把将流量转发到连接在同一机架交换机的节点上,以获得低延时。
75
81
76
82
<!--
77
83
## Using Service Topology
78
84
79
- If your cluster has Service Topology enabled, you can control Service traffic
85
+ If your cluster has the `ServiceTopology`
86
+ [feature gate](/docs/reference/command-line-tools-reference/feature-gates/)
87
+ enabled, you can control Service traffic
80
88
routing by specifying the `topologyKeys` field on the Service spec. This field
81
89
is a preference-order list of Node labels which will be used to sort endpoints
82
90
when accessing this Service. Traffic will be directed to a Node whose value for
83
91
the first label matches the originating Node's value for that label. If there is
84
92
no backend for the Service on a matching Node, then the second label will be
85
93
considered, and so forth, until no labels remain.
86
94
87
- If no match is found, the traffic will be rejected, just as if there were no
95
+ If no match is found, the traffic will be rejected, as if there were no
88
96
backends for the Service at all. That is, endpoints are chosen based on the first
89
97
topology key with available backends. If this field is specified and all entries
90
98
have no backends that match the topology of the client, the service has no
@@ -95,8 +103,9 @@ as the last value in the list.
95
103
96
104
## 使用服务拓扑 {#using-service-topology}
97
105
98
- 如果集群启用了服务拓扑功能后,就可以在 ` Service ` 配置中指定 ` topologyKeys ` 字段,
99
- 从而控制 ` Service ` 的流量路由。
106
+ 如果集群启用了 ` ServiceTopology `
107
+ [ 特性门控] ( /zh/docs/reference/command-line-tools-reference/feature-gates/ ) ,
108
+ 你就可以在 Service 规约中设定 ` topologyKeys ` 字段,从而控制其流量路由。
100
109
此字段是 ` Node ` 标签的优先顺序字段,将用于在访问这个 ` Service ` 时对端点进行排序。
101
110
流量会被定向到第一个标签值和源 ` Node ` 标签值相匹配的 ` Node ` 。
102
111
如果这个 ` Service ` 没有匹配的后端 ` Node ` ,那么第二个标签会被使用做匹配,
@@ -144,7 +153,7 @@ traffic as follows.
144
153
145
154
* Service topology is not compatible with `externalTrafficPolicy=Local`, and
146
155
therefore a Service cannot use both of these features. It is possible to use
147
- both features in the same cluster on different Services, just not on the same
156
+ both features in the same cluster on different Services, only not on the same
148
157
Service.
149
158
150
159
* Valid topology keys are currently limited to `kubernetes.io/hostname`,
@@ -156,11 +165,11 @@ traffic as follows.
156
165
* The catch-all value, `"*"`, must be the last value in the topology keys, if
157
166
it is used.
158
167
-->
159
-
160
168
## 约束条件 {#constraints}
161
169
162
170
* 服务拓扑和 ` externalTrafficPolicy=Local ` 是不兼容的,所以 ` Service ` 不能同时使用这两种特性。
163
- 但是在同一个集群的不同 ` Service ` 上是可以分别使用这两种特性的,只要不在同一个 ` Service ` 上就可以。
171
+ 但是在同一个集群的不同 ` Service ` 上是可以分别使用这两种特性的,只要不在同一个
172
+ ` Service ` 上就可以。
164
173
165
174
* 有效的拓扑键目前只有:` kubernetes.io/hostname ` 、` topology.kubernetes.io/zone ` 和
166
175
` topology.kubernetes.io/region ` ,但是未来会推广到其它的 ` Node ` 标签。
@@ -171,23 +180,21 @@ traffic as follows.
171
180
172
181
<!--
173
182
## Examples
174
- -->
175
- ## 示例
176
183
177
- <!--
178
184
The following are common examples of using the Service Topology feature.
179
185
-->
186
+ ## 示例
187
+
180
188
以下是使用服务拓扑功能的常见示例。
181
189
182
190
<!--
183
191
### Only Node Local Endpoints
184
- -->
185
- ### 仅节点本地端点
186
192
187
- <!--
188
193
A Service that only routes to node local endpoints. If no endpoints exist on the node, traffic is dropped:
189
194
-->
190
- 仅路由到节点本地端点的一种服务。 如果节点上不存在端点,流量则被丢弃:
195
+ ### 仅节点本地端点
196
+
197
+ 仅路由到节点本地端点的一种服务。如果节点上不存在端点,流量则被丢弃:
191
198
192
199
``` yaml
193
200
apiVersion : v1
@@ -207,12 +214,11 @@ spec:
207
214
208
215
<!--
209
216
### Prefer Node Local Endpoints
210
- -->
211
- ### 首选节点本地端点
212
217
213
- <!--
214
218
A Service that prefers node local Endpoints but falls back to cluster wide endpoints if node local endpoints do not exist:
215
219
-->
220
+ ### 首选节点本地端点
221
+
216
222
首选节点本地端点,如果节点本地端点不存在,则回退到集群范围端点的一种服务:
217
223
218
224
` ` ` yaml
@@ -234,13 +240,13 @@ spec:
234
240
235
241
<!--
236
242
### Only Zonal or Regional Endpoints
237
- -->
238
- ### 仅地域或区域端点
239
- <!--
243
+
240
244
A Service that prefers zonal then regional endpoints. If no endpoints exist in either, traffic is dropped.
241
245
-->
242
- 首选地域端点而不是区域端点的一种服务。 如果以上两种范围内均不存在端点,流量则被丢弃。
246
+ ### 仅地域或区域端点
243
247
248
+ 首选地域端点而不是区域端点的一种服务。 如果以上两种范围内均不存在端点,
249
+ 流量则被丢弃。
244
250
245
251
` ` ` yaml
246
252
apiVersion : v1
@@ -261,13 +267,13 @@ spec:
261
267
262
268
<!--
263
269
### Prefer Node Local, Zonal, then Regional Endpoints
264
- -->
265
- ### 优先选择节点本地端点,地域端点,然后是区域端点
266
270
267
- <!--
268
271
A Service that prefers node local, zonal, then regional endpoints but falls back to cluster wide endpoints.
269
272
-->
270
- 优先选择节点本地端点,地域端点,然后是区域端点,然后才是集群范围端点的一种服务。
273
+ ### 优先选择节点本地端点、地域端点,然后是区域端点
274
+
275
+ 优先选择节点本地端点,地域端点,然后是区域端点,最后才是集群范围端点的
276
+ 一种服务。
271
277
272
278
` ` ` yaml
273
279
apiVersion : v1
@@ -296,3 +302,4 @@ spec:
296
302
-->
297
303
* 阅读关于[启用服务拓扑](/zh/docs/tasks/administer-cluster/enabling-service-topology/)
298
304
* 阅读[用服务连接应用程序](/zh/docs/concepts/services-networking/connect-applications-service/)
305
+
0 commit comments