Skip to content

Commit e703cd9

Browse files
authored
Merge pull request #43514 from windsonsea/servy
[zh] Sync /services-networking/service.md
2 parents 3b58bf5 + e8acae5 commit e703cd9

File tree

1 file changed

+66
-54
lines changed
  • content/zh-cn/docs/concepts/services-networking

1 file changed

+66
-54
lines changed

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

Lines changed: 66 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ as a destination.
429429

430430
<!--
431431
For an EndpointSlice that you create yourself, or in your own code,
432-
you should also pick a value to use for the [`endpointslice.kubernetes.io/managed-by`](/docs/reference/labels-annotations-taints/#endpointslicekubernetesiomanaged-by) label.
432+
you should also pick a value to use for the label
433+
[`endpointslice.kubernetes.io/managed-by`](/docs/reference/labels-annotations-taints/#endpointslicekubernetesiomanaged-by).
433434
If you create your own controller code to manage EndpointSlices, consider using a
434435
value similar to `"my-domain.example/name-of-controller"`. If you are using a third
435436
party tool, use the name of the tool in all-lowercase and change spaces and other
@@ -453,7 +454,8 @@ managed by Kubernetes' own control plane.
453454
#### Accessing a Service without a selector {#service-no-selector-access}
454455

455456
Accessing a Service without a selector works the same as if it had a selector.
456-
In the [example](#services-without-selectors) for a Service without a selector, traffic is routed to one of the two endpoints defined in
457+
In the [example](#services-without-selectors) for a Service without a selector,
458+
traffic is routed to one of the two endpoints defined in
457459
the EndpointSlice manifest: a TCP connection to 10.1.2.3 or 10.4.5.6, on port 9376.
458460
-->
459461
#### 访问没有选择算符的 Service {#service-no-selector-access}
@@ -555,8 +557,7 @@ Endpoints API。
555557
<!--
556558
In that case, Kubernetes selects at most 1000 possible backend endpoints to store
557559
into the Endpoints object, and sets an
558-
{{< glossary_tooltip text="annotation" term_id="annotation" >}} on the
559-
Endpoints:
560+
{{< glossary_tooltip text="annotation" term_id="annotation" >}} on the Endpoints:
560561
[`endpoints.kubernetes.io/over-capacity: truncated`](/docs/reference/labels-annotations-taints/#endpoints-kubernetes-io-over-capacity).
561562
The control plane also removes that annotation if the number of backend Pods drops below 1000.
562563
-->
@@ -585,8 +586,8 @@ The same API limit means that you cannot manually update an Endpoints to have mo
585586

586587
<!--
587588
The `appProtocol` field provides a way to specify an application protocol for
588-
each Service port. This is used as a hint for implementations to offer richer
589-
behavior for protocols that they understand.
589+
each Service port. This is used as a hint for implementations to offer
590+
richer behavior for protocols that they understand.
590591
The value of this field is mirrored by the corresponding
591592
Endpoints and EndpointSlice objects.
592593
-->
@@ -690,7 +691,8 @@ Kubernetes Service 类型允许指定你所需要的 Service 类型。
690691
: Exposes the Service on a cluster-internal IP. Choosing this value
691692
makes the Service only reachable from within the cluster. This is the
692693
default that is used if you don't explicitly specify a `type` for a Service.
693-
You can expose the Service to the public internet using an [Ingress](/docs/concepts/services-networking/ingress/) or a
694+
You can expose the Service to the public internet using an
695+
[Ingress](/docs/concepts/services-networking/ingress/) or a
694696
[Gateway](https://gateway-api.sigs.k8s.io/).
695697

696698
[`NodePort`](#type-nodeport)
@@ -734,7 +736,7 @@ Kubernetes Service 类型允许指定你所需要的 Service 类型。
734736
The `type` field in the Service API is designed as nested functionality - each level
735737
adds to the previous. However there is an exception to this nested design. You can
736738
define a `LoadBalancer` Service by
737-
[disabling the load balancer `NodePort` allocation.](/docs/concepts/services-networking/service/#load-balancer-nodeport-allocation)
739+
[disabling the load balancer `NodePort` allocation](/docs/concepts/services-networking/service/#load-balancer-nodeport-allocation).
738740
-->
739741
服务 API 中的 `type` 字段被设计为层层递进的形式 - 每层都建立在前一层的基础上。
740742
但是,这种层层递进的形式有一个例外。
@@ -851,6 +853,27 @@ a NodePort value (30007, in this example):
851853

852854
以下是 `type: NodePort` 服务的一个清单示例,其中指定了 NodePort 值(在本例中为 30007):
853855

856+
<!--
857+
```yaml
858+
apiVersion: v1
859+
kind: Service
860+
metadata:
861+
name: my-service
862+
spec:
863+
type: NodePort
864+
selector:
865+
app.kubernetes.io/name: MyApp
866+
ports:
867+
- port: 80
868+
# By default and for convenience, the `targetPort` is set to
869+
# the same value as the `port` field.
870+
targetPort: 80
871+
# Optional field
872+
# By default and for convenience, the Kubernetes control plane
873+
# will allocate a port from a range (default: 30000-32767)
874+
nodePort: 30007
875+
```
876+
-->
854877
```yaml
855878
apiVersion: v1
856879
kind: Service
@@ -904,8 +927,7 @@ control plane).
904927

905928
If you want to specify particular IP address(es) to proxy the port, you can set the
906929
`--nodeport-addresses` flag for kube-proxy or the equivalent `nodePortAddresses`
907-
field of the
908-
[kube-proxy configuration file](/docs/reference/config-api/kube-proxy-config.v1alpha1/)
930+
field of the [kube-proxy configuration file](/docs/reference/config-api/kube-proxy-config.v1alpha1/)
909931
to particular IP block(s).
910932
-->
911933
#### 为 `type: NodePort` 服务自定义 IP 地址配置 {#service-nodeport-custom-listen-address}
@@ -941,7 +963,8 @@ kube-proxy 应视将其视为所在节点的本机地址。
941963
<!--
942964
This Service is visible as `<NodeIP>:spec.ports[*].nodePort` and `.spec.clusterIP:spec.ports[*].port`.
943965
If the `--nodeport-addresses` flag for kube-proxy or the equivalent field
944-
in the kube-proxy configuration file is set, `<NodeIP>` would be a filtered node IP address (or possibly IP addresses).
966+
in the kube-proxy configuration file is set, `<NodeIP>` would be a filtered
967+
node IP address (or possibly IP addresses).
945968
-->
946969
此 Service 的可见形式为 `<NodeIP>:spec.ports[*].nodePort` 以及 `.spec.clusterIP:spec.ports[*].port`。
947970
如果设置了 kube-proxy 的 `--nodeport-addresses` 标志或 kube-proxy 配置文件中的等效字段,
@@ -1024,7 +1047,8 @@ set is ignored.
10241047
<!--
10251048
The`.spec.loadBalancerIP` field for a Service was deprecated in Kubernetes v1.24.
10261049

1027-
This field was under-specified and its meaning varies across implementations. It also cannot support dual-stack networking. This field may be removed in a future API version.
1050+
This field was under-specified and its meaning varies across implementations.
1051+
It also cannot support dual-stack networking. This field may be removed in a future API version.
10281052
-->
10291053
针对 Service 的 `.spec.loadBalancerIP` 字段已在 Kubernetes v1.24 中被弃用。
10301054

@@ -1174,109 +1198,91 @@ Select one of the tabs.
11741198
{{% tab name="GCP" %}}
11751199

11761200
```yaml
1177-
[...]
11781201
metadata:
1179-
name: my-service
1180-
annotations:
1181-
networking.gke.io/load-balancer-type: "Internal"
1182-
[...]
1202+
name: my-service
1203+
annotations:
1204+
networking.gke.io/load-balancer-type: "Internal"
11831205
```
11841206

11851207
{{% /tab %}}
11861208
{{% tab name="AWS" %}}
11871209

11881210
```yaml
1189-
[...]
11901211
metadata:
11911212
name: my-service
11921213
annotations:
11931214
service.beta.kubernetes.io/aws-load-balancer-internal: "true"
1194-
[...]
11951215
```
11961216

11971217
{{% /tab %}}
11981218
{{% tab name="Azure" %}}
11991219

12001220
```yaml
1201-
[...]
12021221
metadata:
1203-
name: my-service
1204-
annotations:
1205-
service.beta.kubernetes.io/azure-load-balancer-internal: "true"
1206-
[...]
1222+
name: my-service
1223+
annotations:
1224+
service.beta.kubernetes.io/azure-load-balancer-internal: "true"
12071225
```
12081226

12091227
{{% /tab %}}
12101228
{{% tab name="IBM Cloud" %}}
12111229

12121230
```yaml
1213-
[...]
12141231
metadata:
1215-
name: my-service
1216-
annotations:
1217-
service.kubernetes.io/ibm-load-balancer-cloud-provider-ip-type: "private"
1218-
[...]
1232+
name: my-service
1233+
annotations:
1234+
service.kubernetes.io/ibm-load-balancer-cloud-provider-ip-type: "private"
12191235
```
12201236

12211237
{{% /tab %}}
12221238
{{% tab name="OpenStack" %}}
12231239

12241240
```yaml
1225-
[...]
12261241
metadata:
1227-
name: my-service
1228-
annotations:
1229-
service.beta.kubernetes.io/openstack-internal-load-balancer: "true"
1230-
[...]
1242+
name: my-service
1243+
annotations:
1244+
service.beta.kubernetes.io/openstack-internal-load-balancer: "true"
12311245
```
12321246

12331247
{{% /tab %}}
12341248
<!--Baidu Cloud-->
12351249
{{% tab name="百度云" %}}
12361250

12371251
```yaml
1238-
[...]
12391252
metadata:
1240-
name: my-service
1241-
annotations:
1242-
service.beta.kubernetes.io/cce-load-balancer-internal-vpc: "true"
1243-
[...]
1253+
name: my-service
1254+
annotations:
1255+
service.beta.kubernetes.io/cce-load-balancer-internal-vpc: "true"
12441256
```
12451257

12461258
{{% /tab %}}
12471259
<!--Tencent Cloud-->
12481260
{{% tab name="腾讯云" %}}
12491261

12501262
```yaml
1251-
[...]
12521263
metadata:
12531264
annotations:
12541265
service.kubernetes.io/qcloud-loadbalancer-internal-subnetid: subnet-xxxxx
1255-
[...]
12561266
```
12571267

12581268
{{% /tab %}}
12591269
<!--Alibaba Cloud-->
12601270
{{% tab name="阿里云" %}}
12611271

12621272
```yaml
1263-
[...]
12641273
metadata:
12651274
annotations:
12661275
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type: "intranet"
1267-
[...]
12681276
```
12691277

12701278
{{% /tab %}}
12711279
{{% tab name="OCI" %}}
12721280

12731281
```yaml
1274-
[...]
12751282
metadata:
1276-
name: my-service
1277-
annotations:
1278-
service.beta.kubernetes.io/oci-load-balancer-internal: true
1279-
[...]
1283+
name: my-service
1284+
annotations:
1285+
service.beta.kubernetes.io/oci-load-balancer-internal: true
12801286
```
12811287
{{% /tab %}}
12821288
{{< /tabs >}}
@@ -1310,11 +1316,14 @@ spec:
13101316

13111317
{{< note >}}
13121318
<!--
1313-
A Service of `type: ExternalName` accepts an IPv4 address string, but treats that string as a DNS name comprised of digits,
1314-
not as an IP address (the internet does not however allow such names in DNS). Services with external names that resemble IPv4
1319+
A Service of `type: ExternalName` accepts an IPv4 address string,
1320+
but treats that string as a DNS name comprised of digits,
1321+
not as an IP address (the internet does not however allow such names in DNS).
1322+
Services with external names that resemble IPv4
13151323
addresses are not resolved by DNS servers.
13161324

1317-
If you want to map a Service directly to a specific IP address, consider using [headless Services](#headless-services).
1325+
If you want to map a Service directly to a specific IP address, consider using
1326+
[headless Services](#headless-services).
13181327
-->
13191328
`type: ExternalName` 的服务接受 IPv4 地址字符串,但将该字符串视为由数字组成的 DNS 名称,
13201329
而不是 IP 地址(然而,互联网不允许在 DNS 中使用此类名称)。
@@ -1443,7 +1452,8 @@ finding a Service: environment variables and DNS.
14431452
When a Pod is run on a Node, the kubelet adds a set of environment variables
14441453
for each active Service. It adds `{SVCNAME}_SERVICE_HOST` and `{SVCNAME}_SERVICE_PORT` variables,
14451454
where the Service name is upper-cased and dashes are converted to underscores.
1446-
It also supports variables (see [makeLinkVariables](https://github.com/kubernetes/kubernetes/blob/dd2d12f6dc0e654c15d5db57a5f9f6ba61192726/pkg/kubelet/envvars/envvars.go#L72))
1455+
It also supports variables
1456+
(see [makeLinkVariables](https://github.com/kubernetes/kubernetes/blob/dd2d12f6dc0e654c15d5db57a5f9f6ba61192726/pkg/kubelet/envvars/envvars.go#L72))
14471457
that are compatible with Docker Engine's
14481458
"_[legacy container links](https://docs.docker.com/network/links/)_" feature.
14491459

@@ -1674,7 +1684,9 @@ Service 是 Kubernetes REST API 中的顶级资源。你可以找到有关
16741684

16751685
<!--
16761686
Learn more about Services and how they fit into Kubernetes:
1677-
* Follow the [Connecting Applications with Services](/docs/tutorials/services/connect-applications-service/) tutorial.
1687+
1688+
* Follow the [Connecting Applications with Services](/docs/tutorials/services/connect-applications-service/)
1689+
tutorial.
16781690
* Read about [Ingress](/docs/concepts/services-networking/ingress/), which
16791691
exposes HTTP and HTTPS routes from outside the cluster to Services within
16801692
your cluster.
@@ -1691,6 +1703,7 @@ Learn more about Services and how they fit into Kubernetes:
16911703

16921704
<!--
16931705
For more context, read the following:
1706+
16941707
* [Virtual IPs and Service Proxies](/docs/reference/networking/virtual-ips/)
16951708
* [EndpointSlices](/docs/concepts/services-networking/endpoint-slices/)
16961709
* [Service API reference](/docs/reference/kubernetes-api/service-resources/service-v1/)
@@ -1704,4 +1717,3 @@ For more context, read the following:
17041717
* [Service API 参考](/zh-cn/docs/reference/kubernetes-api/service-resources/service-v1/)
17051718
* [EndpointSlice API 参考](/zh-cn/docs/reference/kubernetes-api/service-resources/endpoint-slice-v1/)
17061719
* [Endpoints API 参考](/zh-cn/docs/reference/kubernetes-api/service-resources/endpoints-v1/)
1707-

0 commit comments

Comments
 (0)