Skip to content

Commit 39022f3

Browse files
authored
Merge pull request #37882 from gaogao101/work33
[zh-cn] Update services-networking/service.md
2 parents dedf55e + dee140c commit 39022f3

File tree

1 file changed

+63
-37
lines changed
  • content/zh-cn/docs/concepts/services-networking

1 file changed

+63
-37
lines changed

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

Lines changed: 63 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ The name of a Service object must be a valid
134134
[RFC 1035 label name](/docs/concepts/overview/working-with-objects/names#rfc-1035-label-names).
135135
136136
For example, suppose you have a set of Pods where each listens on TCP port 9376
137-
and contains a label `app=MyApp`:
137+
and contains a label `app.kubernetes.io/name=MyApp`:
138138
-->
139139
## 定义 Service {#defining-a-service}
140140

@@ -143,7 +143,7 @@ Service 在 Kubernetes 中是一个 REST 对象,和 Pod 类似。
143143
Service 对象的名称必须是合法的
144144
[RFC 1035 标签名称](/zh-cn/docs/concepts/overview/working-with-objects/names#rfc-1035-label-names)
145145

146-
例如,假定有一组 Pod,它们对外暴露了 9376 端口,同时还被打上 `app=MyApp` 标签:
146+
例如,假定有一组 Pod,它们对外暴露了 9376 端口,同时还被打上 `app.kubernetes.io/name=MyApp` 标签:
147147

148148
```yaml
149149
apiVersion: v1
@@ -582,7 +582,7 @@ thus is only available to use as-is.
582582

583583
Note that the kube-proxy starts up in different modes, which are determined by its configuration.
584584
- The kube-proxy's configuration is done via a ConfigMap, and the ConfigMap for kube-proxy
585-
effectively deprecates the behaviour for almost all of the flags for the kube-proxy.
585+
effectively deprecates the behavior for almost all of the flags for the kube-proxy.
586586
- The ConfigMap for the kube-proxy does not support live reloading of configuration.
587587
- The ConfigMap parameters for the kube-proxy cannot all be validated and verified on startup.
588588
For example, if your operating system doesn't allow you to run iptables commands,
@@ -603,7 +603,7 @@ Note that the kube-proxy starts up in different modes, which are determined by i
603603
<!--
604604
### User space proxy mode {#proxy-mode-userspace}
605605

606-
In this mode, kube-proxy watches the Kubernetes control plane for the addition and
606+
In this (legacy) mode, kube-proxy watches the Kubernetes control plane for the addition and
607607
removal of Service and Endpoint objects. For each Service it opens a
608608
port (randomly chosen) on the local node. Any connections to this "proxy port"
609609
are proxied to one of the Service's backend Pods (as reported via
@@ -620,7 +620,7 @@ By default, kube-proxy in userspace mode chooses a backend via a round-robin alg
620620
-->
621621
### userspace 代理模式 {#proxy-mode-userspace}
622622

623-
这种模式,kube-proxy 会监视 Kubernetes 控制平面对 Service 对象和 Endpoints 对象的添加和移除操作。
623+
在这种(遗留)模式下,kube-proxy 会监视 Kubernetes 控制平面对 Service 对象和 Endpoints 对象的添加和移除操作。
624624
对每个 Service,它会在本地 Node 上打开一个端口(随机选择)。
625625
任何连接到“代理端口”的请求,都会被代理到 Service 的后端 `Pods` 中的某个上面(如 `Endpoints` 所报告的一样)。
626626
使用哪个后端 Pod,是 kube-proxy 基于 `SessionAffinity` 来确定的。
@@ -639,7 +639,7 @@ In this mode, kube-proxy watches the Kubernetes control plane for the addition a
639639
removal of Service and Endpoint objects. For each Service, it installs
640640
iptables rules, which capture traffic to the Service's `clusterIP` and `port`,
641641
and redirect that traffic to one of the Service's
642-
backend sets. For each Endpoint object, it installs iptables rules which
642+
backend sets. For each Endpoint object, it installs iptables rules which
643643
select a backend Pod.
644644

645645
By default, kube-proxy in iptables mode chooses a backend at random.
@@ -701,7 +701,7 @@ The IPVS proxy mode is based on netfilter hook function that is similar to
701701
iptables mode, but uses a hash table as the underlying data structure and works
702702
in the kernel space.
703703
That means kube-proxy in IPVS mode redirects traffic with lower latency than
704-
kube-proxy in iptables mode, with much better performance when synchronising
704+
kube-proxy in iptables mode, with much better performance when synchronizing
705705
proxy rules. Compared to the other proxy modes, IPVS mode also supports a
706706
higher throughput of network traffic.
707707

@@ -874,7 +874,7 @@ endpoints, the kube-proxy does not forward any traffic for the relevant Service.
874874
<!--
875875
If you enable the `ProxyTerminatingEndpoints`
876876
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/)
877-
`ProxyTerminatingEndpoints` for the kube-proxy, the kube-proxy checks if the node
877+
for the kube-proxy, the kube-proxy checks if the node
878878
has local endpoints and whether or not all the local endpoints are marked as terminating.
879879
-->
880880
如果你启用了 kube-proxy 的 `ProxyTerminatingEndpoints`
@@ -934,7 +934,11 @@ Kubernetes 支持两种基本的服务发现模式 —— 环境变量和 DNS。
934934
### Environment variables
935935

936936
When a Pod is run on a Node, the kubelet adds a set of environment variables
937-
for each active Service. It adds `{SVCNAME}_SERVICE_HOST` and `{SVCNAME}_SERVICE_PORT` variables, where the Service name is upper-cased and dashes are converted to underscores. It also supports variables (see [makeLinkVariables](https://github.com/kubernetes/kubernetes/blob/dd2d12f6dc0e654c15d5db57a5f9f6ba61192726/pkg/kubelet/envvars/envvars.go#L72)) that are compatible with Docker Engine's "_[legacy container links](https://docs.docker.com/network/links/)_" feature.
937+
for each active Service. It adds `{SVCNAME}_SERVICE_HOST` and `{SVCNAME}_SERVICE_PORT` variables,
938+
where the Service name is upper-cased and dashes are converted to underscores.
939+
It also supports variables (see [makeLinkVariables](https://github.com/kubernetes/kubernetes/blob/dd2d12f6dc0e654c15d5db57a5f9f6ba61192726/pkg/kubelet/envvars/envvars.go#L72))
940+
that are compatible with Docker Engine's
941+
"_[legacy container links](https://docs.docker.com/network/links/)_" feature.
938942

939943
For example, the Service `redis-primary` which exposes TCP port 6379 and has been
940944
allocated cluster IP address 10.0.0.11, produces the following environment
@@ -1002,7 +1006,7 @@ create a DNS record for `my-service.my-ns`. Pods in the `my-ns` namespace
10021006
should be able to find the service by doing a name lookup for `my-service`
10031007
(`my-service.my-ns` would also work).
10041008

1005-
Pods in other Namespaces must qualify the name as `my-service.my-ns`. These names
1009+
Pods in other namespaces must qualify the name as `my-service.my-ns`. These names
10061010
will resolve to the cluster IP assigned for the Service.
10071011
-->
10081012
例如,如果你在 Kubernetes 命名空间 `my-ns` 中有一个名为 `my-service` 的服务,
@@ -1145,7 +1149,10 @@ Kubernetes `ServiceTypes` 允许指定你所需要的 Service 类型。
11451149
{{< /note >}}
11461150

11471151
<!--
1148-
You can also use [Ingress](/docs/concepts/services-networking/ingress/) to expose your Service. Ingress is not a Service type, but it acts as the entry point for your cluster. It lets you consolidate your routing rules into a single resource as it can expose multiple services under the same IP address.
1152+
You can also use [Ingress](/docs/concepts/services-networking/ingress/) to expose your Service.
1153+
Ingress is not a Service type, but it acts as the entry point for your cluster.
1154+
It lets you consolidate your routing rules into a single resource as it can expose multiple
1155+
services under the same IP address.
11491156
-->
11501157
你也可以使用 [Ingress](/zh-cn/docs/concepts/services-networking/ingress/) 来暴露自己的服务。
11511158
Ingress 不是一种服务类型,但它充当集群的入口点。
@@ -1260,10 +1267,6 @@ kube-proxy only selects the loopback interface for NodePort Services.
12601267
The default for `--nodeport-addresses` is an empty list.
12611268
This means that kube-proxy should consider all available network interfaces for NodePort.
12621269
(That's also compatible with earlier Kubernetes releases.)
1263-
Note that this Service is visible as `<NodeIP>:spec.ports[*].nodePort`
1264-
and `.spec.clusterIP:spec.ports[*].port`.
1265-
If the `--nodeport-addresses` flag for kube-proxy or the equivalent field
1266-
in the kube-proxy configuration file is set, `<NodeIP>` would be a filtered node IP address (or possibly IP addresses).
12671270
-->
12681271
此标志采用逗号分隔的 IP 段列表(例如 `10.0.0.0/8`、`192.0.2.0/25`)来指定 kube-proxy 应视为该节点本地的
12691272
IP 地址范围。
@@ -1273,9 +1276,17 @@ IP 地址范围。
12731276
`--nodeport-addresses` 的默认值是一个空列表。
12741277
这意味着 kube-proxy 应考虑 NodePort 的所有可用网络接口。
12751278
(这也与早期的 Kubernetes 版本兼容。)
1276-
请注意,此服务显示为 `<NodeIP>:spec.ports[*].nodePort` 和 `.spec.clusterIP:spec.ports[*].port`。
1279+
1280+
{{< note >}}
1281+
<!--
1282+
This Service is visible as `<NodeIP>:spec.ports[*].nodePort` and `.spec.clusterIP:spec.ports[*].port`.
1283+
If the `--nodeport-addresses` flag for kube-proxy or the equivalent field
1284+
in the kube-proxy configuration file is set, `<NodeIP>` would be a filtered node IP address (or possibly IP addresses).
1285+
-->
1286+
此服务呈现为 `<NodeIP>:spec.ports[*].nodePort` 和 `.spec.clusterIP:spec.ports[*].port`。
12771287
如果设置了 kube-proxy 的 `--nodeport-addresses` 标志或 kube-proxy 配置文件中的等效字段,
12781288
则 `<NodeIP>` 将是过滤的节点 IP 地址(或可能的 IP 地址)。
1289+
{{< /note >}}
12791290

12801291
<!--
12811292
### Type LoadBalancer {#loadbalancer}
@@ -1317,7 +1328,8 @@ status:
13171328
```
13181329

13191330
<!--
1320-
Traffic from the external load balancer is directed at the backend Pods. The cloud provider decides how it is load balanced.
1331+
Traffic from the external load balancer is directed at the backend Pods.
1332+
The cloud provider decides how it is load balanced.
13211333
-->
13221334
来自外部负载均衡器的流量将直接重定向到后端 Pod 上,不过实际它们是如何工作的,这要依赖于云提供商。
13231335

@@ -1439,13 +1451,13 @@ LoadBalancer 类型的服务继续分配节点端口。
14391451
`spec.loadBalancerClass` enables you to use a load balancer implementation other than the cloud provider default.
14401452
By default, `spec.loadBalancerClass` is `nil` and a `LoadBalancer` type of Service uses
14411453
the cloud provider's default load balancer implementation if the cluster is configured with
1442-
a cloud provider using the `--cloud-provider` component flag.
1454+
a cloud provider using the `--cloud-provider` component flag.
14431455
If `spec.loadBalancerClass` is specified, it is assumed that a load balancer
14441456
implementation that matches the specified class is watching for Services.
14451457
Any default load balancer implementation (for example, the one provided by
14461458
the cloud provider) will ignore Services that have this field set.
14471459
`spec.loadBalancerClass` can be set on a Service of type `LoadBalancer` only.
1448-
Once set, it cannot be changed.
1460+
Once set, it cannot be changed.
14491461
-->
14501462
`spec.loadBalancerClass` 允许你不使用云提供商的默认负载均衡器实现,转而使用指定的负载均衡器实现。
14511463
默认情况下,`.spec.loadBalancerClass` 的取值是 `nil`,如果集群使用 `--cloud-provider` 配置了云提供商,
@@ -1469,7 +1481,8 @@ Unprefixed names are reserved for end-users.
14691481
In a mixed environment it is sometimes necessary to route traffic from Services inside the same
14701482
(virtual) network address block.
14711483

1472-
In a split-horizon DNS environment you would need two Services to be able to route both external and internal traffic to your endpoints.
1484+
In a split-horizon DNS environment you would need two Services to be able to route both external
1485+
and internal traffic to your endpoints.
14731486

14741487
To set an internal load balancer, add one of the following annotations to your Service
14751488
depending on the cloud Service provider you're using.
@@ -1667,7 +1680,9 @@ TCP 和 SSL 选择第4层代理:ELB 转发流量而不修改报头。
16671680
In the above example, if the Service contained three ports, `80`, `443`, and
16681681
`8443`, then `443` and `8443` would use the SSL certificate, but `80` would be proxied HTTP.
16691682

1670-
From Kubernetes v1.9 onwards you can use [predefined AWS SSL policies](https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-security-policy-table.html) with HTTPS or SSL listeners for your Services.
1683+
From Kubernetes v1.9 onwards you can use
1684+
[predefined AWS SSL policies](https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-security-policy-table.html)
1685+
with HTTPS or SSL listeners for your Services.
16711686
To see which policies are available for use, you can use the `aws` command line tool:
16721687
-->
16731688
在上例中,如果服务包含 `80`、`443` 和 `8443` 三个端口, 那么 `443` 和 `8443` 将使用 SSL 证书,
@@ -1777,7 +1792,8 @@ Connection draining for Classic ELBs can be managed with the annotation
17771792
`service.beta.kubernetes.io/aws-load-balancer-connection-draining-enabled` set
17781793
to the value of `"true"`. The annotation
17791794
`service.beta.kubernetes.io/aws-load-balancer-connection-draining-timeout` can
1780-
also be used to set maximum time, in seconds, to keep the existing connections open before deregistering the instances.
1795+
also be used to set maximum time, in seconds, to keep the existing connections open before
1796+
deregistering the instances.
17811797
-->
17821798
#### AWS 上的连接排空
17831799

@@ -1879,7 +1895,8 @@ To use a Network Load Balancer on AWS, use the annotation `service.beta.kubernet
18791895

18801896
{{< note >}}
18811897
<!--
1882-
NLB only works with certain instance classes; see the [AWS documentation](http://docs.aws.amazon.com/elasticloadbalancing/latest/network/target-group-register-targets.html#register-deregister-targets)
1898+
NLB only works with certain instance classes; see the
1899+
[AWS documentation](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/target-group-register-targets.html#register-deregister-targets)
18831900
on Elastic Load Balancing for a list of supported instance types.
18841901
-->
18851902
NLB 仅适用于某些实例类。有关受支持的实例类型的列表,
@@ -2066,7 +2083,8 @@ spec:
20662083

20672084
{{< note >}}
20682085
<!--
2069-
ExternalName accepts an IPv4 address string, but as a DNS name comprised of digits, not as an IP address. ExternalNames that resemble IPv4 addresses are not resolved by CoreDNS or ingress-nginx because ExternalName
2086+
ExternalName accepts an IPv4 address string, but as a DNS name comprised of digits, not as an IP address.
2087+
ExternalNames that resemble IPv4 addresses are not resolved by CoreDNS or ingress-nginx because ExternalName
20702088
is intended to specify a canonical DNS name. To hardcode an IP address, consider using
20712089
[headless Services](#headless-services).
20722090
-->
@@ -2091,9 +2109,13 @@ Service's `type`.
20912109

20922110
{{< warning >}}
20932111
<!--
2094-
You may have trouble using ExternalName for some common protocols, including HTTP and HTTPS. If you use ExternalName then the hostname used by clients inside your cluster is different from the name that the ExternalName references.
2112+
You may have trouble using ExternalName for some common protocols, including HTTP and HTTPS.
2113+
If you use ExternalName then the hostname used by clients inside your cluster is different from
2114+
the name that the ExternalName references.
20952115

2096-
For protocols that use hostnames this difference may lead to errors or unexpected responses. HTTP requests will have a `Host:` header that the origin server does not recognize; TLS servers will not be able to provide a certificate matching the hostname that the client connected to.
2116+
For protocols that use hostnames this difference may lead to errors or unexpected responses.
2117+
HTTP requests will have a `Host:` header that the origin server does not recognize;
2118+
TLS servers will not be able to provide a certificate matching the hostname that the client connected to.
20972119
-->
20982120
对于一些常见的协议,包括 HTTP 和 HTTPS,你使用 ExternalName 可能会遇到问题。
20992121
如果你使用 ExternalName,那么集群内客户端使用的主机名与 ExternalName 引用的名称不同。
@@ -2219,7 +2241,7 @@ fail with a message indicating an IP address could not be allocated.
22192241
In the control plane, a background controller is responsible for creating that
22202242
map (needed to support migrating from older versions of Kubernetes that used
22212243
in-memory locking). Kubernetes also uses controllers to check for invalid
2222-
assignments (eg due to administrator intervention) and for cleaning up allocated
2244+
assignments (e.g. due to administrator intervention) and for cleaning up allocated
22232245
IP addresses that are no longer used by any Services.
22242246
-->
22252247
### 避免冲突 {#avoiding-collisions}
@@ -2374,8 +2396,11 @@ through a load-balancer, though in those cases the client IP does get altered.
23742396
#### IPVS
23752397

23762398
<!--
2377-
iptables operations slow down dramatically in large scale cluster e.g 10,000 Services.
2378-
IPVS is designed for load balancing and based on in-kernel hash tables. So you can achieve performance consistency in large number of Services from IPVS-based kube-proxy. Meanwhile, IPVS-based kube-proxy has more sophisticated load balancing algorithms (least conns, locality, weighted, persistence).
2399+
iptables operations slow down dramatically in large scale cluster e.g. 10,000 Services.
2400+
IPVS is designed for load balancing and based on in-kernel hash tables.
2401+
So you can achieve performance consistency in large number of Services from IPVS-based kube-proxy.
2402+
Meanwhile, IPVS-based kube-proxy has more sophisticated load balancing algorithms
2403+
(least conns, locality, weighted, persistence).
23792404
-->
23802405
在大规模集群(例如 10000 个服务)中,iptables 操作会显着降低速度。
23812406
IPVS 专为负载均衡而设计,并基于内核内哈希表。
@@ -2386,14 +2411,15 @@ IPVS 专为负载均衡而设计,并基于内核内哈希表。
23862411
## API Object
23872412

23882413
Service is a top-level resource in the Kubernetes REST API. You can find more details
2389-
about the API object at: [Service API object](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#service-v1-core).
2414+
about the [Service API object](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#service-v1-core).
23902415

23912416
## Supported protocols {#protocol-support}
23922417
-->
23932418
## API 对象 {#api-object}
23942419

2395-
Service 是 Kubernetes REST API 中的顶级资源。你可以在以下位置找到有关 API 对象的更多详细信息:
2396-
[Service 对象 API](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#service-v1-core).
2420+
Service 是 Kubernetes REST API 中的顶级资源。你可以找到有关
2421+
[Service 对象 API](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#service-v1-core)
2422+
的更多详细信息。
23972423

23982424
## 受支持的协议 {#protocol-support}
23992425

@@ -2437,7 +2463,8 @@ provider offering this facility. (Most do not).
24372463

24382464
{{< warning >}}
24392465
<!--
2440-
The support of multihomed SCTP associations requires that the CNI plugin can support the assignment of multiple interfaces and IP addresses to a Pod.
2466+
The support of multihomed SCTP associations requires that the CNI plugin can support the
2467+
assignment of multiple interfaces and IP addresses to a Pod.
24412468

24422469
NAT for multihomed SCTP associations requires special logic in the corresponding kernel modules.
24432470
-->
@@ -2483,7 +2510,7 @@ HTTP/HTTPS 反向代理,并将其转发到该服务的 Endpoints。
24832510
{{< note >}}
24842511
<!--
24852512
You can also use {{< glossary_tooltip term_id="ingress" >}} in place of Service
2486-
to expose HTTP / HTTPS Services.
2513+
to expose HTTP/HTTPS Services.
24872514
-->
24882515
你还可以使用 {{< glossary_tooltip text="Ingress" term_id="ingress" >}} 代替
24892516
Service 来公开 HTTP/HTTPS 服务。
@@ -2522,11 +2549,10 @@ followed by the data from the client.
25222549
## {{% heading "whatsnext" %}}
25232550
25242551
<!--
2525-
* Read [Connecting Applications with Services](/docs/concepts/services-networking/connect-applications-service/)
2552+
* Follow the [Connecting Applications with Services](/docs/tutorials/services/connect-applications-service/) tutorial
25262553
* Read about [Ingress](/docs/concepts/services-networking/ingress/)
25272554
* Read about [EndpointSlices](/docs/concepts/services-networking/endpoint-slices/)
25282555
-->
2529-
* 阅读[使用服务访问应用](/zh-cn/docs/concepts/services-networking/connect-applications-service/)
2556+
* 遵循[使用 Service 连接到应用](/zh-cn/docs/tutorials/services/connect-applications-service/)教程
25302557
* 阅读了解 [Ingress](/zh-cn/docs/concepts/services-networking/ingress/)
25312558
* 阅读了解[端点切片(Endpoint Slices)](/zh-cn/docs/concepts/services-networking/endpoint-slices/)
2532-

0 commit comments

Comments
 (0)