Skip to content

Commit d0cf73f

Browse files
authored
Merge pull request #44341 from windsonsea/serviy
[zh] Add translations to /services-networking/service.md
2 parents fb17d6e + 7e190f9 commit d0cf73f

File tree

1 file changed

+93
-24
lines changed
  • content/zh-cn/docs/concepts/services-networking

1 file changed

+93
-24
lines changed

content/zh-cn/docs/concepts/services-networking/service.md

Lines changed: 93 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ title: 服务(Service)
33
feature:
44
title: 服务发现与负载均衡
55
description: >
6-
你无需修改应用来使用陌生的服务发现机制。Kubernetes 为每个 Pod 提供了自己的 IP 地址并为一组 Pod 提供一个 DNS 名称,并且可以在它们之间实现负载均衡。
6+
你无需修改应用来使用陌生的服务发现机制。Kubernetes 为每个 Pod 提供了自己的 IP 地址并为一组
7+
Pod 提供一个 DNS 名称,并且可以在它们之间实现负载均衡。
78
description: >-
89
将在集群中运行的应用通过同一个面向外界的端点公开出去,即使工作负载分散于多个后端也完全可行。
910
content_type: concept
@@ -36,8 +37,7 @@ an older app you've containerized. You use a Service to make that set of Pods av
3637
on the network so that clients can interact with it.
3738
-->
3839
Kubernetes 中 Service 的一个关键目标是让你无需修改现有应用以使用某种不熟悉的服务发现机制。
39-
你可以在 Pod 集合中运行代码,无论该代码是为云原生环境设计的,
40-
还是被容器化的老应用。
40+
你可以在 Pod 集合中运行代码,无论该代码是为云原生环境设计的,还是被容器化的老应用。
4141
你可以使用 Service 让一组 Pod 可在网络上访问,这样客户端就能与之交互。
4242

4343
<!--
@@ -241,7 +241,7 @@ A Service can map _any_ incoming `port` to a `targetPort`. By default and
241241
for convenience, the `targetPort` is set to the same value as the `port`
242242
field.
243243
-->
244-
Service 能够将任意入站 `port` 映射到某个 `targetPort`。
244+
Service 能够将**任意**入站 `port` 映射到某个 `targetPort`。
245245
默认情况下,出于方便考虑,`targetPort` 会被设置为与 `port` 字段相同的值。
246246
{{< /note >}}
247247

@@ -373,6 +373,31 @@ object manually. For example:
373373
由于此 Service 没有选择算符,因此不会自动创建对应的 EndpointSlice(和旧版的 Endpoints)对象。
374374
你可以通过手动添加 EndpointSlice 对象,将 Service 映射到该服务运行位置的网络地址和端口:
375375

376+
<!--
377+
```yaml
378+
apiVersion: discovery.k8s.io/v1
379+
kind: EndpointSlice
380+
metadata:
381+
name: my-service-1 # by convention, use the name of the Service
382+
# as a prefix for the name of the EndpointSlice
383+
labels:
384+
# You should set the "kubernetes.io/service-name" label.
385+
# Set its value to match the name of the Service
386+
kubernetes.io/service-name: my-service
387+
addressType: IPv4
388+
ports:
389+
- name: '' # empty because port 9376 is not assigned as a well-known
390+
# port (by IANA)
391+
appProtocol: http
392+
protocol: TCP
393+
port: 9376
394+
endpoints:
395+
- addresses:
396+
- "10.4.5.6"
397+
- addresses:
398+
- "10.1.2.3"
399+
```
400+
-->
376401
```yaml
377402
apiVersion: discovery.k8s.io/v1
378403
kind: EndpointSlice
@@ -898,22 +923,21 @@ spec:
898923
-->
899924
#### 预留 NodePort 端口范围以避免发生冲突 {#avoid-nodeport-collisions}
900925
901-
{{< feature-state for_k8s_version="v1.28" state="beta" >}}
926+
{{< feature-state for_k8s_version="v1.29" state="stable" >}}
902927
903928
<!--
904929
The policy for assigning ports to NodePort services applies to both the auto-assignment and
905930
the manual assignment scenarios. When a user wants to create a NodePort service that
906931
uses a specific port, the target port may conflict with another port that has already been assigned.
907-
In this case, you can enable the feature gate `ServiceNodePortStaticSubrange`, which allows you
908-
to use a different port allocation strategy for NodePort Services. The port range for NodePort services
909-
is divided into two bands. Dynamic port assignment uses the upper band by default, and it may use
910-
the lower band once the upper band has been exhausted. Users can then allocate from the lower band
911-
with a lower risk of port collision.
932+
933+
To avoid this problem, the port range for NodePort services is divided into two bands.
934+
Dynamic port assignment uses the upper band by default, and it may use the lower band once the
935+
upper band has been exhausted. Users can then allocate from the lower band with a lower risk of port collision.
912936
-->
913937
为 NodePort 服务分配端口的策略既适用于自动分配的情况,也适用于手动分配的场景。
914938
当某个用于希望创建一个使用特定端口的 NodePort 服务时,该目标端口可能与另一个已经被分配的端口冲突。
915-
这时,你可以启用特性门控 `ServiceNodePortStaticSubrange`,进而为 NodePort Service
916-
使用不同的端口分配策略。用于 NodePort 服务的端口范围被分为两段。
939+
940+
为了避免这个问题,用于 NodePort 服务的端口范围被分为两段。
917941
动态端口分配默认使用较高的端口段,并且在较高的端口段耗尽时也可以使用较低的端口段。
918942
用户可以从较低端口段中分配端口,降低端口冲突的风险。
919943
@@ -1168,6 +1192,50 @@ Unprefixed names are reserved for end-users.
11681192
可以有选择地带有类似 "`internal-vip`" 或 "`example.com/internal-vip`" 这类前缀。
11691193
没有前缀的名字是保留给最终用户的。
11701194

1195+
<!--
1196+
#### Specifying IPMode of load balancer status {#load-balancer-ip-mode}
1197+
-->
1198+
#### 指定负载均衡器状态的 IPMode {#load-balancer-ip-mode}
1199+
1200+
{{< feature-state for_k8s_version="v1.29" state="alpha" >}}
1201+
1202+
<!--
1203+
Starting as Alpha in Kubernetes 1.29,
1204+
a [feature gate](/docs/reference/command-line-tools-reference/feature-gates/)
1205+
named `LoadBalancerIPMode` allows you to set the `.status.loadBalancer.ingress.ipMode`
1206+
for a Service with `type` set to `LoadBalancer`.
1207+
The `.status.loadBalancer.ingress.ipMode` specifies how the load-balancer IP behaves.
1208+
It may be specified only when the `.status.loadBalancer.ingress.ip` field is also specified.
1209+
-->
1210+
这是从 Kubernetes 1.29 开始的一个 Alpha 级别特性,通过名为 `LoadBalancerIPMode`
1211+
的[特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/)允许你为
1212+
`type` 为 `LoadBalancer` 的服务设置 `.status.loadBalancer.ingress.ipMode`。
1213+
`.status.loadBalancer.ingress.ipMode` 指定负载均衡器 IP 的行为方式。
1214+
此字段只能在 `.status.loadBalancer.ingress.ip` 字段也被指定时才能指定。
1215+
1216+
<!--
1217+
There are two possible values for `.status.loadBalancer.ingress.ipMode`: "VIP" and "Proxy".
1218+
The default value is "VIP" meaning that traffic is delivered to the node
1219+
with the destination set to the load-balancer's IP and port.
1220+
There are two cases when setting this to "Proxy", depending on how the load-balancer
1221+
from the cloud provider delivers the traffics:
1222+
-->
1223+
`.status.loadBalancer.ingress.ipMode` 有两个可能的值:"VIP" 和 "Proxy"。
1224+
默认值是 "VIP",意味着流量被传递到目的地设置为负载均衡器 IP 和端口的节点上。
1225+
将此字段设置为 "Proxy" 时会出现两种情况,具体取决于云驱动提供的负载均衡器如何传递流量:
1226+
1227+
<!--
1228+
- If the traffic is delivered to the node then DNATed to the pod, the destination would be set to the node's IP and node port;
1229+
- If the traffic is delivered directly to the pod, the destination would be set to the pod's IP and port.
1230+
-->
1231+
- 如果流量被传递到节点,然后 DNAT 到 Pod,则目的地将被设置为节点的 IP 和节点端口;
1232+
- 如果流量被直接传递到 Pod,则目的地将被设置为 Pod 的 IP 和端口。
1233+
1234+
<!--
1235+
Service implementations may use this information to adjust traffic routing.
1236+
-->
1237+
服务实现可以使用此信息来调整流量路由。
1238+
11711239
<!--
11721240
#### Internal load balancer
11731241

@@ -1184,16 +1252,18 @@ depending on the cloud service provider you're using:
11841252

11851253
在混合环境中,有时有必要在同一(虚拟)网络地址段内路由来自 Service 的流量。
11861254

1187-
在水平分割(Split-Horizon) DNS 环境中,你需要两个 Service 才能将内部和外部流量都路由到你的端点。
1255+
在水平分割(Split-Horizon)DNS 环境中,你需要两个 Service 才能将内部和外部流量都路由到你的端点。
11881256

11891257
如要设置内部负载均衡器,请根据你所使用的云平台,为 Service 添加以下注解之一:
11901258

11911259
{{< tabs name="service_tabs" >}}
11921260
{{% tab name="Default" %}}
1261+
11931262
<!--
11941263
Select one of the tabs.
11951264
-->
11961265
选择一个标签。
1266+
11971267
{{% /tab %}}
11981268
{{% tab name="GCP" %}}
11991269

@@ -1245,7 +1315,9 @@ metadata:
12451315
```
12461316

12471317
{{% /tab %}}
1248-
<!--Baidu Cloud-->
1318+
<!--
1319+
Baidu Cloud
1320+
-->
12491321
{{% tab name="百度云" %}}
12501322

12511323
```yaml
@@ -1256,7 +1328,9 @@ metadata:
12561328
```
12571329

12581330
{{% /tab %}}
1259-
<!--Tencent Cloud-->
1331+
<!--
1332+
Tencent Cloud
1333+
-->
12601334
{{% tab name="腾讯云" %}}
12611335

12621336
```yaml
@@ -1266,7 +1340,9 @@ metadata:
12661340
```
12671341

12681342
{{% /tab %}}
1269-
<!--Alibaba Cloud-->
1343+
<!--
1344+
Alibaba Cloud
1345+
-->
12701346
{{% tab name="阿里云" %}}
12711347

12721348
```yaml
@@ -1452,10 +1528,6 @@ finding a Service: environment variables and DNS.
14521528
When a Pod is run on a Node, the kubelet adds a set of environment variables
14531529
for each active Service. It adds `{SVCNAME}_SERVICE_HOST` and `{SVCNAME}_SERVICE_PORT` variables,
14541530
where the Service name is upper-cased and dashes are converted to underscores.
1455-
It also supports variables
1456-
(see [makeLinkVariables](https://github.com/kubernetes/kubernetes/blob/dd2d12f6dc0e654c15d5db57a5f9f6ba61192726/pkg/kubelet/envvars/envvars.go#L72))
1457-
that are compatible with Docker Engine's
1458-
"_[legacy container links](https://docs.docker.com/network/links/)_" feature.
14591531

14601532
For example, the Service `redis-primary` which exposes TCP port 6379 and has been
14611533
allocated cluster IP address 10.0.0.11, produces the following environment
@@ -1466,9 +1538,6 @@ variables:
14661538
当 Pod 运行在某 Node 上时,kubelet 会在其中为每个活跃的 Service 添加一组环境变量。
14671539
kubelet 会添加环境变量 `{SVCNAME}_SERVICE_HOST` 和 `{SVCNAME}_SERVICE_PORT`。
14681540
这里 Service 的名称被转为大写字母,横线被转换成下划线。
1469-
它还支持与 Docker Engine 的 "**[legacy container links](https://docs.docker.com/network/links/)**"
1470-
特性兼容的变量
1471-
(参阅 [makeLinkVariables](https://github.com/kubernetes/kubernetes/blob/dd2d12f6dc0e654c15d5db57a5f9f6ba61192726/pkg/kubelet/envvars/envvars.go#L72)) 。
14721541

14731542
例如,一个 Service `redis-primary` 公开了 TCP 端口 6379,
14741543
同时被分配了集群 IP 地址 10.0.0.11,这个 Service 生成的环境变量如下:
@@ -1594,7 +1663,7 @@ to control how Kubernetes routes traffic to healthy (“ready”) backends.
15941663

15951664
See [Traffic Policies](/docs/reference/networking/virtual-ips/#traffic-policies) for more details.
15961665
-->
1597-
### 流量策略
1666+
### 流量策略 {#traffic-policies}
15981667

15991668
你可以设置 `.spec.internalTrafficPolicy` 和 `.spec.externalTrafficPolicy`
16001669
字段来控制 Kubernetes 如何将流量路由到健康(“就绪”)的后端。

0 commit comments

Comments
 (0)