@@ -54,7 +54,6 @@ to, so that the frontend can use the backend part of the workload?
54
54
55
55
Enter _Services_.
56
56
-->
57
-
58
57
## 动机
59
58
60
59
创建和销毁 Kubernetes {{< glossary_tooltip term_id="pod" text="Pod" >}} 以匹配集群的期望状态。
@@ -132,7 +131,6 @@ The name of a Service object must be a valid
132
131
For example, suppose you have a set of Pods where each listens on TCP port 9376
133
132
and contains a label `app=MyApp`:
134
133
-->
135
-
136
134
## 定义 Service
137
135
138
136
Service 在 Kubernetes 中是一个 REST 对象,和 Pod 类似。
@@ -149,16 +147,16 @@ metadata:
149
147
name : my-service
150
148
spec :
151
149
selector :
152
- app : MyApp
150
+ app.kubernetes.io/name : MyApp
153
151
ports :
154
152
- protocol : TCP
155
153
port : 80
156
154
targetPort : 9376
157
155
` ` `
158
156
159
157
<!--
160
- This specification creates a new Service object named “ my-service” , which
161
- targets TCP port 9376 on any Pod with the ` app=MyApp` label.
158
+ This specification creates a new Service object named " my-service" , which
159
+ targets TCP port 9376 on any Pod with the ` app.kubernetes.io/name =MyApp` label.
162
160
163
161
Kubernetes assigns this Service an IP address (sometimes called the "cluster IP"),
164
162
which is used by the Service proxies
@@ -169,7 +167,7 @@ match its selector, and then POSTs any updates to an Endpoint object
169
167
also named "my-service".
170
168
-->
171
169
上述配置创建一个名称为 "my-service" 的 Service 对象,它会将请求代理到使用
172
- TCP 端口 9376,并且具有标签 `" app=MyApp" ` 的 Pod 上。
170
+ TCP 端口 9376,并且具有标签 `app.kubernetes.io/name =MyApp` 的 Pod 上。
173
171
174
172
Kubernetes 为该服务分配一个 IP 地址(有时称为 “集群 IP”),该 IP 地址由服务代理使用。
175
173
(请参见下面的 [VIP 和 Service 代理](#virtual-ips-and-service-proxies)).
@@ -209,7 +207,7 @@ spec:
209
207
ports:
210
208
- containerPort: 80
211
209
name: http-web-svc
212
-
210
+
213
211
---
214
212
apiVersion: v1
215
213
kind: Service
@@ -337,8 +335,8 @@ Endpoint IP addresses cannot be the cluster IPs of other Kubernetes Services,
337
335
because {{< glossary_tooltip term_id="kube-proxy" >}} doesn't support virtual IPs
338
336
as a destination.
339
337
-->
340
- 端点 IPs _必须不可以_ 是:本地回路(IPv4 的 127.0.0.0/8, IPv6 的 ::1/128)或
341
- 本地链接 (IPv4 的 169.254.0.0/16 和 224.0.0.0/24,IPv6 的 fe80::/64)。
338
+ 端点 IPs **必须不可以** 是:本地回路(IPv4 的 127.0.0.0/8, IPv6 的 ::1/128)
339
+ 或本地链接 (IPv4 的 169.254.0.0/16 和 224.0.0.0/24,IPv6 的 fe80::/64)。
342
340
343
341
端点 IP 地址不能是其他 Kubernetes 服务的集群 IP,因为
344
342
{{< glossary_tooltip term_id ="kube-proxy">}} 不支持将虚拟 IP 作为目标。
@@ -666,7 +664,7 @@ metadata:
666
664
name: my-service
667
665
spec:
668
666
selector:
669
- app: MyApp
667
+ app.kubernetes.io/name : MyApp
670
668
ports:
671
669
- name: http
672
670
protocol: TCP
@@ -1100,7 +1098,7 @@ metadata:
1100
1098
spec:
1101
1099
type: NodePort
1102
1100
selector:
1103
- app: MyApp
1101
+ app.kubernetes.io/name : MyApp
1104
1102
ports:
1105
1103
# 默认情况下,为了方便起见,` targetPort` 被设置为与 `port` 字段相同的值。
1106
1104
- port : 80
@@ -1136,7 +1134,7 @@ metadata:
1136
1134
name: my-service
1137
1135
spec:
1138
1136
selector:
1139
- app: MyApp
1137
+ app.kubernetes.io/name : MyApp
1140
1138
ports:
1141
1139
- protocol: TCP
1142
1140
port: 80
@@ -1146,7 +1144,7 @@ spec:
1146
1144
status:
1147
1145
loadBalancer:
1148
1146
ingress:
1149
- - ip: 192.0.2.127
1147
+ - ip: 192.0.2.127
1150
1148
` ` `
1151
1149
1152
1150
<!--
@@ -2061,22 +2059,22 @@ Kubernetes 通过在为 API 服务器配置的 `service-cluster-ip-range` CIDR
2061
2059
<!--
2062
2060
# ### IP address ranges for `type: ClusterIP` Services {#service-ip-static-sub-range}
2063
2061
2064
- {{< feature-state for_k8s_version="v1.24 " state="alpha " >}}
2062
+ {{< feature-state for_k8s_version="v1.25 " state="beta " >}}
2065
2063
However, there is a problem with this `ClusterIP` allocation strategy, because a user
2066
2064
can also [choose their own address for the service](#choosing-your-own-ip-address).
2067
2065
This could result in a conflict if the internal allocator selects the same IP address
2068
2066
for another Service.
2069
2067
-->
2070
2068
# ### `type: ClusterIP` 服务的 IP 地址范围 {#service-ip-static-sub-range}
2071
2069
2072
- {{< feature-state for_k8s_version="v1.24 " state="alpha " >}}
2070
+ {{< feature-state for_k8s_version="v1.25 " state="beta " >}}
2073
2071
但是,这种 `ClusterIP` 分配策略存在一个问题,因为用户还可以[为服务选择自己的地址](#choosing-your-own-ip-address)。
2074
2072
如果内部分配器为另一个服务选择相同的 IP 地址,这可能会导致冲突。
2075
2073
2076
2074
<!--
2077
- If you enable the `ServiceIPStaticSubrange`
2078
- [feature gate](/docs/reference/command-line-tools-reference/feature-gates/),
2079
- the allocation strategy divides the `ClusterIP` range into two bands, based on
2075
+ The `ServiceIPStaticSubrange`
2076
+ [feature gate](/docs/reference/command-line-tools-reference/feature-gates/) is enabled by default in v1.25
2077
+ and later, using an allocation strategy that divides the `ClusterIP` range into two bands, based on
2080
2078
the size of the configured `service-cluster-ip-range` by using the following formula
2081
2079
` min(max(16, cidrSize / 16), 256)` , described as _never less than 16 or more than 256,
2082
2080
with a graduated step function between them_. Dynamic IP allocations will be preferentially
@@ -2085,8 +2083,8 @@ assigned from the lower band.
2085
2083
This allows users to use the lower band of the `service-cluster-ip-range` for their
2086
2084
Services with static IPs assigned with a very low risk of running into conflicts.
2087
2085
-->
2088
- 如果启用 `ServiceIPStaticSubrange`[特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/),
2089
- 分配策略根据配置的 `service-cluster-ip-range` 的大小,使用以下公式
2086
+ ` ServiceIPStaticSubrange` [特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/)在
2087
+ v1.25 及后续版本中默认启用,其分配策略根据配置的 `service-cluster-ip-range` 的大小,使用以下公式
2090
2088
` min(max(16, cidrSize / 16), 256)` 进行划分,该公式可描述为
2091
2089
“在不小于 16 且不大于 256 之间有一个步进量(Graduated Step)”,将
2092
2090
` ClusterIP` 范围分成两段。动态 IP 分配将优先从上半段地址中选择,
@@ -2225,11 +2223,8 @@ depends on the cloud provider offering this facility.
2225
2223
你可以将 UDP 用于大多数服务。 对于 type=LoadBalancer 服务,对 UDP 的支持取决于提供此功能的云提供商。
2226
2224
2227
2225
<!--
2228
-
2229
2226
# ## SCTP
2230
2227
2231
- {{< feature-state for_k8s_version="v1.20" state="stable" >}}
2232
-
2233
2228
When using a network plugin that supports SCTP traffic, you can use SCTP for
2234
2229
most Services. For type=LoadBalancer Services, SCTP support depends on the cloud
2235
2230
provider offering this facility. (Most do not).
@@ -2250,42 +2245,38 @@ provider offering this facility. (Most do not).
2250
2245
2251
2246
# #### 支持多宿主 SCTP 关联 {#caveat-sctp-multihomed}
2252
2247
2253
- <!--
2254
2248
{{< warning >}}
2249
+ <!--
2255
2250
The support of multihomed SCTP associations requires that the CNI plugin can support the assignment of multiple interfaces and IP addresses to a Pod.
2256
2251
2257
2252
NAT for multihomed SCTP associations requires special logic in the corresponding kernel modules.
2258
- {{< /warning >}}
2259
2253
-->
2260
- {{< warning >}}
2261
2254
支持多宿主SCTP关联要求 CNI 插件能够支持为一个 Pod 分配多个接口和 IP 地址。
2262
2255
2263
2256
用于多宿主 SCTP 关联的 NAT 在相应的内核模块中需要特殊的逻辑。
2264
2257
{{< /warning >}}
2265
2258
2266
2259
<!--
2267
2260
# #### Windows {#caveat-sctp-windows-os}
2268
-
2269
- {{< note >}}
2270
- SCTP is not supported on Windows based nodes.
2271
- {{< /note >}}
2272
2261
-->
2273
2262
# #### Windows {#caveat-sctp-windows-os}
2274
2263
2275
2264
{{< note >}}
2265
+ <!--
2266
+ SCTP is not supported on Windows based nodes.
2267
+ -->
2276
2268
基于 Windows 的节点不支持 SCTP。
2277
2269
{{< /note >}}
2278
2270
2279
2271
<!--
2280
2272
# #### Userspace kube-proxy {#caveat-sctp-kube-proxy-userspace}
2281
-
2282
- {{< warning >}}
2283
- The kube-proxy does not support the management of SCTP associations when it is in userspace mode.
2284
- {{< /warning >}}
2285
2273
-->
2286
2274
# #### 用户空间 kube-proxy {#caveat-sctp-kube-proxy-userspace}
2287
2275
2288
2276
{{< warning >}}
2277
+ <!--
2278
+ The kube-proxy does not support the management of SCTP associations when it is in userspace mode.
2279
+ -->
2289
2280
当 kube-proxy 处于用户空间模式时,它不支持 SCTP 关联的管理。
2290
2281
{{< /warning >}}
2291
2282
@@ -2343,7 +2334,7 @@ followed by the data from the client.
2343
2334
<!--
2344
2335
* Read [Connecting Applications with Services](/docs/concepts/services-networking/connect-applications-service/)
2345
2336
* Read about [Ingress](/docs/concepts/services-networking/ingress/)
2346
- * Read about [Endpoint Slices ](/docs/concepts/services-networking/endpoint-slices/)
2337
+ * Read about [EndpointSlices ](/docs/concepts/services-networking/endpoint-slices/)
2347
2338
-->
2348
2339
* 阅读[使用服务访问应用](/zh-cn/docs/concepts/services-networking/connect-applications-service/)
2349
2340
* 阅读了解 [Ingress](/zh-cn/docs/concepts/services-networking/ingress/)
0 commit comments