Skip to content

Commit 5a97e2b

Browse files
authored
Merge pull request #22079 from ydcool/zh-trans-service
update zh trans for concepts/services-networking/service.md
2 parents b225af9 + 06cda78 commit 5a97e2b

File tree

1 file changed

+80
-10
lines changed
  • content/zh/docs/concepts/services-networking

1 file changed

+80
-10
lines changed

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

Lines changed: 80 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: Services
55
feature:
66
title: 服务发现与负载均衡
77
description: >
8-
无需修改您的应用程序即可使用陌生的服务发现机制。Kubernetes 为容器提供了自己的 IP 地址和一个 DNS 名称,并且可以在它们之间实现负载平衡
8+
无需修改您的应用程序即可使用陌生的服务发现机制。Kubernetes 为容器提供了自己的 IP 地址和一个 DNS 名称,并且可以在它们之间实现负载均衡
99
1010
content_type: concept
1111
weight: 10
@@ -328,6 +328,27 @@ Endpoint 切片是一种 API 资源,可以为 Endpoint 提供更可扩展的
328328

329329
Endpoint 切片提供了附加的属性和功能,这些属性和功能在 [Endpoint 切片](/docs/concepts/services-networking/endpoint-slices/)中进行了详细描述。
330330

331+
<!--
332+
### Application protocol
333+
334+
{{< feature-state for_k8s_version="v1.18" state="alpha" >}}
335+
336+
The AppProtocol field provides a way to specify an application protocol to be
337+
used for each Service port.
338+
339+
As an alpha feature, this field is not enabled by default. To use this field,
340+
enable the `ServiceAppProtocol` [feature
341+
gate](/docs/reference/command-line-tools-reference/feature-gates/).
342+
-->
343+
### 应用程序协议
344+
345+
{{< feature-state for_k8s_version="v1.18" state="alpha" >}}
346+
347+
AppProtocol 字段提供了一种为每个 Service 端口指定应用程序协议的方式。
348+
349+
作为一个 alpha 特性,该字段默认未启用。要使用该字段,请启用 `ServiceAppProtocol` [特性开关]
350+
(/docs/reference/command-line-tools-reference/feature-gates/)。
351+
331352
<!--
332353
## Virtual IPs and service proxies
333354

@@ -868,6 +889,25 @@ to just expose one or more nodes' IPs directly.
868889

869890
Note that this Service is visible as `<NodeIP>:spec.ports[*].nodePort`
870891
and `.spec.clusterIP:spec.ports[*].port`. (If the `--nodeport-addresses` flag in kube-proxy is set, <NodeIP> would be filtered NodeIP(s).)
892+
893+
For example:
894+
```yaml
895+
apiVersion: v1
896+
kind: Service
897+
metadata:
898+
name: my-service
899+
spec:
900+
type: NodePort
901+
selector:
902+
app: MyApp
903+
ports:
904+
# By default and for convenience, the `targetPort` is set to the same value as the `port` field.
905+
- port: 80
906+
targetPort: 80
907+
# Optional field
908+
# By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767)
909+
nodePort: 30007
910+
```
871911
-->
872912
873913
### NodePort 类型
@@ -891,6 +931,25 @@ and `.spec.clusterIP:spec.ports[*].port`. (If the `--nodeport-addresses` flag in
891931

892932
需要注意的是,Service 能够通过 `<NodeIP>:spec.ports[*].nodePort` 和 `spec.clusterIp:spec.ports[*].port` 而对外可见。
893933

934+
例如:
935+
```yaml
936+
apiVersion: v1
937+
kind: Service
938+
metadata:
939+
name: my-service
940+
spec:
941+
type: NodePort
942+
selector:
943+
app: MyApp
944+
ports:
945+
# 默认情况下,为了方便起见,`targetPort` 被设置为与 `port` 字段相同的值。
946+
- port: 80
947+
targetPort: 80
948+
# 可选字段
949+
# 默认情况下,为了方便起见,Kubernetes 控制平面会从某个范围内分配一个端口号(默认:30000-32767)
950+
nodePort: 30007
951+
```
952+
894953
<!--
895954
### Type LoadBalancer {#loadbalancer}
896955
@@ -1032,6 +1091,16 @@ metadata:
10321091
[...]
10331092
```
10341093
{{% /tab %}}
1094+
{{% tab name="IBM Cloud" %}}
1095+
```yaml
1096+
[...]
1097+
metadata:
1098+
name: my-service
1099+
annotations:
1100+
service.kubernetes.io/ibm-load-balancer-cloud-provider-ip-type: "private"
1101+
[...]
1102+
```
1103+
{{% /tab %}}
10351104
{{% tab name="OpenStack" %}}
10361105
```yaml
10371106
[...]
@@ -1561,7 +1630,7 @@ worth understanding.
15611630
One of the primary philosophies of Kubernetes is that you should not be
15621631
exposed to situations that could cause your actions to fail through no fault
15631632
of your own. For the design of the Service resource, this means not making
1564-
you choose your own port number for a if that choice might collide with
1633+
you choose your own port number if that choice might collide with
15651634
someone else's choice. That is an isolation failure.
15661635

15671636
In order to allow you to choose a port number for your Services, we must
@@ -1576,7 +1645,7 @@ fail with a message indicating an IP address could not be allocated.
15761645

15771646
In the control plane, a background controller is responsible for creating that
15781647
map (needed to support migrating from older versions of Kubernetes that used
1579-
in-memory locking). Kubernetes also uses controllers to checking for invalid
1648+
in-memory locking). Kubernetes also uses controllers to check for invalid
15801649
assignments (eg due to administrator intervention) and for cleaning up allocated
15811650
IP addresses that are no longer used by any Services.
15821651

@@ -1585,15 +1654,16 @@ IP addresses that are no longer used by any Services.
15851654
### 避免冲突
15861655

15871656
Kubernetes 最主要的哲学之一,是用户不应该暴露那些能够导致他们操作失败、但又不是他们的过错的场景。
1588-
这种场景下,让我们来看一下网络端口 —— 用户不应该必须选择一个端口号,而且该端口还有可能与其他用户的冲突。
1589-
这就是说,在彼此隔离状态下仍然会出现失败。
1657+
对于 Service 资源的设计,这意味着如果用户的选择有可能与他人冲突,那就不要让用户自行选择端口号。
1658+
这是一个隔离性的失败。
1659+
1660+
为了使用户能够为他们的 Service 选择一个端口号,我们必须确保不能有2个 Service 发生冲突。
1661+
Kubernetes 通过为每个 Service 分配它们自己的 IP 地址来实现。
15901662

1591-
为了使用户能够为他们的 `Service` 选择一个端口号,我们必须确保不能有2个 `Service` 发生冲突
1592-
我们可以通过为每个 `Service` 分配它们自己的 IP 地址来实现
1663+
为了保证每个 Service 被分配到一个唯一的 IP,需要一个内部的分配器能够原子地更新 {{< glossary_tooltip term_id="etcd" >}} 中的一个全局分配映射表,这个更新操作要先于创建每一个 Service
1664+
为了使 Service 能够获取到 IP,这个映射表对象必须在注册中心存在,否则创建 Service 将会失败,指示一个 IP 不能被分配
15931665

1594-
为了保证每个 `Service` 被分配到一个唯一的 IP,需要一个内部的分配器能够原子地更新 etcd 中的一个全局分配映射表,这个更新操作要先于创建每一个 `Service`。
1595-
为了使 `Service` 能够获取到 IP,这个映射表对象必须在注册中心存在,否则创建 `Service` 将会失败,指示一个 IP 不能被分配。
1596-
一个后台 Controller 的职责是创建映射表(从 Kubernetes 的旧版本迁移过来,旧版本中是通过在内存中加锁的方式实现),并检查由于管理员干预和清除任意 IP 造成的不合理分配,这些 IP 被分配了但当前没有 `Service` 使用它们。
1666+
在控制平面中,一个后台 Controller 的职责是创建映射表(需要支持从使用了内存锁的 Kubernetes 的旧版本迁移过来)。同时 Kubernetes 会通过控制器检查不合理的分配(如管理员干预导致的)以及清理已被分配但不再被任何 Service 使用的 IP 地址。
15971667

15981668
<!--
15991669
### Service IP addresses {#ips-and-vips}

0 commit comments

Comments
 (0)